查看系统中创建的字符串对象

发布于 2024-09-12 10:22:40 字数 969 浏览 4 评论 0原文

我想查看系统中创建的字符串对象的值。为此,我使用 Xbootclasspath 选项覆盖 String.class。在我的新重写类中,我通过向每个构造函数添加 System.out.println(value) 行来修改 String.class 的构造函数,这样,

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

但我收到了错误,

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)

如果有人可以指出我如何查看创建的字符串对象,我会很高兴的。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似梦非梦 2024-09-19 10:22:40

这意味着 System.out 为空。事实上,在加载某些类时,会创建一个新的 String 并且 System.out 字段尚未初始化。

您应该推迟打印,或者可能只是将有关创建的字符串的信息保留在私有字段中,然后使用调试器等查看该字段。

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.

长亭外,古道边 2024-09-19 10:22:40

我猜想在 System.out 初始化之前已经创建了字符串。
如果您可以在早期程序阶段忽略这些字符串,也许您可​​以尝试以下操作:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文