You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Marcono1234 (Jira)" <ji...@apache.org> on 2022/09/11 13:56:00 UTC

[jira] [Created] (IO-780) ReaderInputStream discards some encoding errors

Marcono1234 created IO-780:
------------------------------

             Summary: ReaderInputStream discards some encoding errors
                 Key: IO-780
                 URL: https://issues.apache.org/jira/browse/IO-780
             Project: Commons IO
          Issue Type: Bug
          Components: Streams/Writers
    Affects Versions: 2.11.0
            Reporter: Marcono1234


h3. Description
{{org.apache.commons.io.input.ReaderInputStream}} discards encoder errors in some cases instead of properly rethrowing them.

The underlying issue is that {{lastCoderResult}} is re-assigned before it has been checked for errors or overflow.

This was originally mentioned in pull request [#293](https://github.com/apache/commons-io/pull/293).

h3. Example
The {{read()}} call in the following example should throw an exception, but currently it erroneously returns -1.
{code}
// Encoder which throws on malformed or unmappable input
CharsetEncoder encoder = StandardCharsets.UTF_8.newEncoder();
ReaderInputStream in = new ReaderInputStream(new StringReader("\uD800"), encoder);
// BUG: This should have thrown an exception because the input is malformed
System.out.println("Read: " + in.read());
{code}




--
This message was sent by Atlassian Jira
(v8.20.10#820010)