Marcono1234 created IO-717:
------------------------------

             Summary: ReaderInputStream does not throw exception with 
CodingErrorAction.REPORT
                 Key: IO-717
                 URL: https://issues.apache.org/jira/browse/IO-717
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 2.8.0
            Reporter: Marcono1234


{{org.apache.commons.io.input.ReaderInputStream}} constructed with a 
{{CharsetEncoder}} with {{CodingErrorAction.REPORT}} does not throw exceptions 
when unmappable or malformed input is encountered. And in some cases can even 
enter infinite loops.

Example:
{code}
CharsetEncoder encoder = 
StandardCharsets.UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPORT);
try (InputStream in = new ReaderInputStream(new StringReader("\uD800aa"), 
encoder, 2)) {
    in.read();
}
{code}

The reason for this is that the class does not check 
[{{CoderResult.isError()}}|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/charset/CoderResult.html#isError()]
 and then call 
[{{CoderResult.throwException()}}|https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/charset/CoderResult.html#throwException()].

----

It would also be good to improve the documentation of the constructors taking a 
{{Charset}} or charset name to describe that they replace unmappable or 
malformed input with the default replacement character.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to