-
Bug
-
Resolution: Fixed
-
P4
-
None
-
b130
-
Verified
Compile and java-p this:
class Foo {
static final String s = "\1\2\3";
static String f() { return s; }
}
The tool outputs control characters which most terminals do not display.
This is a problem when strings are used to carry binary data.
Escapes are needed to visualize the class file contents in this case.
Suggestion: four-digit unicode escapes, such as \u0001\u0002\u0003.
Note that the classfile printer (used by the javap -constant option) displays all characters using \uNNNN, except 7-bit printables. This would be acceptable also, though it make it hard to see most unicode characters.
In any case, control characters *must* be escaped.
Suggested fix:
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
@@ -385,6 +385,11 @@
sb.append('\\').append('\\');
break;
default:
+ if (Character.isISOControl(c)) {
+ sb.append(String.format("\\u%04x", (int) c));
+ break;
+ }
+ // or copy logic of ClassWriter::esc = (c < 32 || c > 126)
sb.append(c);
}
}
class Foo {
static final String s = "\1\2\3";
static String f() { return s; }
}
The tool outputs control characters which most terminals do not display.
This is a problem when strings are used to carry binary data.
Escapes are needed to visualize the class file contents in this case.
Suggestion: four-digit unicode escapes, such as \u0001\u0002\u0003.
Note that the classfile printer (used by the javap -constant option) displays all characters using \uNNNN, except 7-bit printables. This would be acceptable also, though it make it hard to see most unicode characters.
In any case, control characters *must* be escaped.
Suggested fix:
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
@@ -385,6 +385,11 @@
sb.append('\\').append('\\');
break;
default:
+ if (Character.isISOControl(c)) {
+ sb.append(String.format("\\u%04x", (int) c));
+ break;
+ }
+ // or copy logic of ClassWriter::esc = (c < 32 || c > 126)
sb.append(c);
}
}
- relates to
-
JDK-8085386 Constant pool's strings are not escaped properly
-
- Resolved
-