[英]module java.base does not read module java.desktop
When I run this test (using jmockit and TestNG, not sure if that's relevant): 当我运行此测试时(使用jmockit和TestNG,不确定是否相关):
public class Test {
@Test public void test(@Mocked ProcessBuilder pb) throws IOException {
new Expectations() {{ pb.start(); result = null; }};
assertNull(m());
}
public static Process m() throws IOException {
return new ProcessBuilder("").start();
}
}
I get this exception: 我得到这个例外:
java.lang.IllegalAccessError: class java.lang.ProcessBuilder (in module java.base) cannot access class javax.print.PrintException (in module java.desktop) because module java.base does not read module java.desktop
at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java)
....
I am using build 177. 我正在使用build 177。
I can rerun the test using --add-reads java.base=java.desktop
argument and it works fine but I don't really understand what is happening here. 我可以使用
--add-reads java.base=java.desktop
参数重新运行测试,它工作正常,但我真的不明白这里发生了什么。
Why am I getting that exception? 为什么我得到那个例外?
The IllegalAccessError hints that JMockit has instrumented ProcessBuilder (in java.base) with a reference to an exception in the java.desktop module. IllegalAccessError提示JMockit已经在java.desktop模块中引用了异常的ProcessBuilder(在java.base中)。 I don't know why it choose this exception, that may be something for the JMockit mailing list.
我不知道它为什么选择这个例外,这可能是JMockit邮件列表的内容。 However it does explain why
--add-reads
fixes the issue. 但它确实解释了为什么
--add-reads
修复了这个问题。
The issue has been fixed for JMockit 1.34. 该问题已针对JMockit 1.34修复。
During startup, JMockit modifies a JRE class (adding a few fields) in order to provide support for the mocking of JRE classes. 在启动期间,JMockit修改了一个JRE类(添加了几个字段),以便为JRE类的模拟提供支持。 The actual class which gets modified is arbitrary, and
javax.print.PrintException
was used (as a secondary choice) just because it usually never gets loaded in a typical test run. 被修改的实际类是任意的,并且
javax.print.PrintException
(作为次要选择),因为它通常永远不会在典型的测试运行中加载。 On JDK 9, this class is not accessible from the "base" module, so it was now replaced by another one which is. 在JDK 9上,无法从“base”模块访问此类,因此它现在被另一个类替换。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.