I want to se开发者_StackOverflow中文版e the values of the created string objects in the system. To do so, I override the String.class by using Xbootclasspath option. In my new overriding class I modified constructors of String.class by adding the line System.out.println(value) to each, such that
public String() {
this.offset = 0;
this.count = 0;
this.value = new char[0];
System.out.println(value);
}
But I got the error,
Error occurred during initialization of VM
java.lang.ExceptionInInitializerError
at java.lang.Runtime.loadLibrary0(Runtime.java:819)
at java.lang.System.loadLibrary(System.java:1030)
at java.lang.System.initializeSystemClass(System.java:1077)
Caused by: java.lang.NullPointerException
at java.lang.String.<init>(String.java:219)
at java.lang.StringBuilder.toString(StringBuilder.java:430)
at java.io.File.<clinit>(File.java:167)
at java.lang.Runtime.loadLibrary0(Runtime.java:819)
at java.lang.System.loadLibrary(System.java:1030)
at java.lang.System.initializeSystemClass(System.java:1077)
If anyone can point me on how to see the created string objects, I would be really glad.
It means System.out
is null. In fact while loading some classes, a new String
is created and the System.out
field has not been yet initialized.
You should deffer the printing, or may be just keep information about created string in a private field and latter have a look on this field using debugger for example.
I guess there are Strings being created before System.out is initialized. If you can ignore these Strings in the early program phase, maybe you could try something like:
if (System.out != null)
System.out.println(value);
精彩评论