RFR(S) 8227868: jinfo and jstack can fail converting UTF8 output to strings
Severin Gehwolf
sgehwolf at redhat.com
Thu Jul 18 12:00:10 UTC 2019
On Thu, 2019-07-18 at 10:07 +0000, Schmelter, Ralf wrote:
> Please review this fix. It applies the same correction to jstack and
> jinfo which was already applied to jcmd. To avoid code duplication, I
> moved the actual code to a utility class.
>
> webrev:
> http://cr.openjdk.java.net/~rschmelter/webrevs/8227868/webrev.0/
> bugreport: https://bugs.openjdk.java.net/browse/JDK-8227868
+ /**
+ * Reads characters in UTF-8 format from the input stream and prints them
+ * with the given print stream. Closes the input stream before it returns.
+ *
+ * @return The number of printed characters.
+ */
+ public static long drainUTF8(InputStream is, PrintStream ps) throws IOException {
+ long result = 0;
+
+ try (BufferedInputStream bis = new BufferedInputStream(is);
+ InputStreamReader isr = new InputStreamReader(bis, "UTF-8")) {
+ char c[] = new char[8192];
+ int n;
+
+ do {
+ n = isr.read(c);
+
+ if (n > 0) {
+ result += n;
+ System.out.print(n == c.length ? c : Arrays.copyOf(c, n));
+ }
If I read this right, then the method doesn't do what it claims it
does. It's printing to System.out unconditionally instead of to 'ps'.
What am I missing?
Would it be possible to add regression tests for this? Along the lines
of test/jdk/sun/tools/jstack/BasicJStackTest.java
Thanks,
Severin
More information about the serviceability-dev
mailing list