See Created String Objects in the System

I want to see the values ​​of the created string objects in the system. To do this, I override String.class using the Xbootclasspath option. In my new override class, I modified the String.class constructors by adding a System.out.println (value) line to each line, such that

public String() {
 this.offset = 0;
 this.count = 0;
 this.value = new char[0];
 System.out.println(value);
}

But I got an 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 tell me how to see the created string objects, I would be very happy.

+3
source share
2 answers

This means that System.outit is null. In fact, when loading some classes, a new one is created String, and the field System.outhas not yet been initialized.

, - , , .

+2

, System.out. , , - :

if (System.out != null) 
  System.out.println(value);
0

Source: https://habr.com/ru/post/1756880/


All Articles