You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2021/02/17 16:20:00 UTC

[jira] [Commented] (IO-717) ReaderInputStream does not throw exception with CodingErrorAction.REPORT

    [ https://issues.apache.org/jira/browse/IO-717?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17285947#comment-17285947 ] 

Gary D. Gregory commented on IO-717:
------------------------------------

[~Marcono1234]
Thank you for your report.
Feel free to provide a PR on GitHub with tests ;-)


> 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
>            Priority: Major
>
> {{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)