You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Daniel Vega (Jira)" <ji...@apache.org> on 2026/03/13 17:33:00 UTC
[jira] [Updated] (IO-887) WriterOutputStream fails on malformed input by default
[ https://issues.apache.org/jira/browse/IO-887?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Vega updated IO-887:
---------------------------
Summary: WriterOutputStream fails on malformed input by default (was: WriterOutputStream.builder fails on malformed input by default)
> WriterOutputStream fails on malformed input by default
> ------------------------------------------------------
>
> 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
> Priority: Minor
>
> {{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)