我是靠谱客的博主 失眠小虾米,最近开发中收集的这篇文章主要介绍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.

最后

以上就是失眠小虾米为你收集整理的java.base is not on,模块java.base无法读取模块java.desktop的全部内容,希望文章能够帮你解决java.base is not on,模块java.base无法读取模块java.desktop所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部