This rule flags the following Java class constructors that take a java.io.OutputStream
and no charset :
java.io.PrintStreamjava.io.PrintWriterjava.io.OutputStreamWriter
The constructor signatures that take OutputStream without Charset parameters default to use the Charset.defaultCharset() encoding.
This causes an issue if the OutputStream to wrap is a PrintStream, which holds its own charset, leading it to ignored.
This is especially problematic when PrintWriter wraps System.out/err, because with the
JEP400
,
the default charset is now UTF-8 while standard I/O remains in native.encoding.
As part of this change, java.io.PrintStream now defines a charset() method to return the print stream's charset.
For more information see JDK-8276970