Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See the created string objects in the system

I want to see 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.

like image 723
user385435 Avatar asked Mar 11 '26 20:03

user385435


1 Answers

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.

like image 200
Manuel Selva Avatar answered Mar 13 '26 13:03

Manuel Selva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!