[ 
https://issues.apache.org/jira/browse/IO-887?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory updated IO-887:
-------------------------------
    Summary: WriterOutputStream from a builder fails on malformed or unmappable 
input bytes  (was: WriterOutputStream fails on malformed input by default for 
malformed or unmappable input bytes)

> WriterOutputStream from a builder fails on malformed or unmappable input bytes
> ------------------------------------------------------------------------------
>
>                 Key: IO-887
>                 URL: https://issues.apache.org/jira/browse/IO-887
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Streams/Writers
>    Affects Versions: 2.12.0
>            Reporter: Daniel Vega
>            Assignee: Gary D. Gregory
>            Priority: Minor
>             Fix For: 2.22.0
>
>
> {{WriterOutputStream}} switched from using constructors to builders in 
> commons.io 2.12.0
> Prior to that change, you usually did something like this:
> {code:java}
> var wos = new WriterOutputStream(writer, StandardCharsets.UTF_8)
> {code}
> After version 2.12.0 you need to migrate that code. If you follow [the 
> documentation|https://github.com/apache/commons-io/blob/350a4bff8e17bf549300307394922ed8a9c7e158/src/main/java/org/apache/commons/io/output/WriterOutputStream.java#L60-L63]
>  you write:
> {code:java}
> var wos = WriterOutputStream.builder()
>     .setWriter(writer)
>     .setCharset(cs)
>     .get();
> {code}
> The first minor annoyance is that this throws {{IOException}} and the 
> previous no. Nothing serious. But the mayor problem is that this is not 
> equivalent to the code before. The compatible change is:
> {code:java}
>     var decoder = StandardCharsets.UTF_8
>         .newDecoder()
>         .onMalformedInput(CodingErrorAction.REPLACE)
>         .onUnmappableCharacter(CodingErrorAction.REPLACE)
>         .replaceWith("?");
>     var wos = WriterOutputStream.builder()
>         .setWriter(writer)
>         .setCharsetDecoder(decoder)
>         .get();
> {code}
> This change in behavior is not documented and caused some issues. It seems 
> that the current default for Decoder creation is not sane as it raise 
> IOException on malformed/unmappable Input



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

Reply via email to