简体   繁体   English

为什么对rt.jar进行简单更改会导致Java Runtime Environment无声崩溃?

[英]Why's a simple change to rt.jar causing the Java Runtime Environment to crash silently?

This is what I'm doing: 这就是我正在做的事情:

  1. extract contents of my JRE's rt.jar 提取我的JRE的rt.jar的内容
  2. extract src.zip of my JDK (same version) 提取我的JDK的src.zip(相同版本)

Now, if I copy Runtime.java from the extracted src folder and compile it using javac.exe without any modifications and then put it in the extracted rt folder to finally put everything back in a jar file using jar.exe, everything works as expected. 现在,如果我从提取的src文件夹中复制Runtime.java并使用javac.exe进行编译而不进行任何修改,然后将其放入解压缩的rt文件夹中,最后使用jar.exe将所有内容放回到jar文件中,一切都按预期工作。 The JRE runs fine. JRE运行良好。

However, if I make the slightest change to Runtime.java and compile it and put it in rt.jar, the JRE crashes whenever I attempt to start it. 但是,如果我对Runtime.java进行最轻微的更改并将其编译并放入rt.jar,那么只要我尝试启动它,JRE就会崩溃。 This is an example of a slight change that causes the silent crash: 这是导致无声崩溃的轻微更改的示例:

/** Don't let anyone else instantiate this class */
    private Runtime() {
        System.out.println("This is a test.");
    }

Instead of: 代替:

/** Don't let anyone else instantiate this class */
    private Runtime() {}

Could anyone tell me why this is causing my JRE to crash? 谁能告诉我为什么这会导致我的JRE崩溃?

Thanks in advance. 提前致谢。

It's possible that System.out has not been initialised at the time that the Runtime() constructor runs. Runtime()构造函数运行Runtime()System.out可能尚未初始化。 Usually console output is not considered a "slight" change, but at the wrong time it can invoke way too much stuff that may not be set up at all yet. 通常控制台输出不被视为“轻微”改变,但在错误的时间它可以调用太多可能根本没有设置的东西。

You're doing this all wrong. 你这样做是错的。 You can't distribute that modified JRE for a start, so it is only useful inside your organization . 您无法在一开始就分发修改后的JRE,因此它仅在您的组织内部有用。 Install a SecurityManager and don't grant your codebase any of the RuntimePermissions you're trying to protect against. 安装SecurityManager并且不要向您的代码库授予您尝试防范的任何RuntimePermissions。

@Tom - I advise you NOT to try to do this: @Tom - 我建议你不要试图这样做:

  • You cannot distribute the modified rt.jar file without violating the Sun binary license. 您不能在不违反Sun二进制许可证的情况下分发修改后的rt.jar文件。

  • Even if you did, you would not be allowed to call it Java. 即使你这样做,你也不会被称为Java。

  • As you are finding, there are lots of complications that arise when you make changes, particularly when those changes might interfere with the JVM's behind the scenes initialization. 正如您所发现的那样,进行更改时会出现许多复杂情况,尤其是当这些更改可能会干扰JVM的幕后初始化时。 And when things blow up during initialization, the JVM often cannot report the problem in an intelligible way. 当初始化期间事情爆发时,JVM通常无法以可理解的方式报告问题。

  • If you do succeed in making the modified rt.jar work for one JRE, there is no guarantee that the same hacks will work for a different version. 如果您成功地使修改后的rt.jar适用于一个JRE,则无法保证相同的hack将适用于其他版本。

  • Nobody in their right mind would knowingly use a modified JVM (especially one modified by a third-party) in a production app. 在他们的正确思想中,没有人会故意在生产应用程序中使用经过修改的JVM(尤其是由第三方修改的JVM)。

EDIT : judging from your other questions, I guess you are trying to reverse engineer or modify some third party Java application with a custom launcher. 编辑 :从您的其他问题判断,我想您正在尝试使用自定义启动器逆向工程或修改某些第三方Java应用程序。 If you provided more information on what you were really trying to do, we might be able to suggest the right way to do it ... rather than using "desperate measures" such as modifying the JRE. 如果您提供了有关您真正想要做的事情的更多信息,我们可能会建议正确的方法...而不是使用“绝望的措施”,例如修改JRE。

That's pretty strange, as I did the same trick with many classes in rt.jar in past. 这很奇怪,因为我在过去的rt.jar中使用了很多类。

Can you provide us with the crashed process output? 你能为我们提供崩溃的过程输出吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM