On Sun, 14 Nov 2021 16:45:07 GMT, Ichiroh Takiguchi <itakigu...@openjdk.org> wrote:
>> Good suggestions. Filed a JBS issue: >> https://bugs.openjdk.java.net/browse/JDK-8276970 > > Hello @naotoj . > For PrintStream.getCharset(), following changes may be required. > > +++ src/java.base/share/classes/java/io/OutputStreamWriter.java > + Charset getCharset() { > + return se.getCharset(); > + } > > +++ src/java.base/share/classes/java/io/PrintStream.java > + public Charset getCharset() { > + return charOut.getCharset(); > + } > > +++ src/java.base/share/classes/sun/nio/cs/StreamEncoder.java > + public Charset getCharset() { > + return cs; > + } > > For javac code, we may not use PrintStream.getCharset() directly because > javac code is compiled by boot compiler. > We need to use reflection, like: > > +++ src/jdk.compiler/share/classes/com/sun/tools/javac/util/Log.java > + private static Charset getCharset(PrintStream ps) { > + try { > + Method getCharset = > PrintStream.class.getDeclaredMethod("getCharset"); > + return (Charset)getCharset.invoke(ps); > + } catch (Exception e) { > + return Charset.defaultCharset(); > + } > + } > > If we add following constructors against PrintWriter, we just change javap > and jshell code. > But I cannot evaluate this code changes. > > +++ src/java.base/share/classes/java/io/PrintWriter.java > + public PrintWriter(PrintStream ps) { > + this((OutputStream)ps, false, ps.getCharset()); > + } > + public PrintWriter(PrintStream ps, boolean autoFlush) { > + this((OutputStream)ps, autoFlush, ps.getCharset()); > + } > > I really appreciate if you handle this kind of code change via JEP-400. I think this PR can now safely be withdrawn, as https://github.com/openjdk/jdk/pull/6401 is now integrated. @takiguc, if you do not mind, I will create a PR for the remaining jshell issue. Please let me know. ------------- PR: https://git.openjdk.java.net/jdk/pull/5771