java.base is not on,模块java.base无法读取模块java.desktop

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();

}

}

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.

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.

Why am I getting that exception?

解决方案

The issue has been fixed for 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. 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值