模块java.base无法读取模块java.desktop [英] module java.base does not read module java.desktop
问题描述
当我运行此测试时(使用jmockit和TestNG,不确定是否相关):
When I run this test (using jmockit and TestNG, not sure if that's relevant):
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();
}
}
我收到此异常:
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)
....
我正在使用版本177.
I am using build 177.
我可以使用--add-reads java.base=java.desktop
参数重新运行测试,它可以正常工作,但是我不太了解这里发生了什么.
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.
我为什么会收到该例外?
推荐答案
问题已修复为JMockit 1.34.
The issue has been fixed for JMockit 1.34.
在启动期间,JMockit会修改JRE类(添加一些字段),以便为JRE类的模拟提供支持.被修改的实际类是任意的,并且使用javax.print.PrintException
(作为次要选择)只是因为它通常不会在典型的测试运行中加载.在JDK 9上,无法从基本"模块访问此类,因此现在已被另一个替代.
During startup, JMockit modifies a JRE class (adding a few fields) in order to provide support for the mocking of JRE classes. 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. On JDK 9, this class is not accessible from the "base" module, so it was now replaced by another one which is.
这篇关于模块java.base无法读取模块java.desktop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!