简体   繁体   English

模块java.base不读取模块java.desktop

[英]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.

相关问题 java.desktop 无法解析为模块 - java.desktop cannot be resolved to a module 如何在 Proguard 中包含 java.desktop 模块作为库 jar - How to include java.desktop module as a library jar in Proguard 如何修复 Android Studio 中的“module java.base does not "opens java.io" to unnamed module'' 错误? - How to fix the ''module java.base does not "opens java.io" to unnamed module '' error in Android Studio? 使用Java 9运行应用程序,模块java.base不会“打开java.io” - Running application with Java 9, module java.base does not “opens java.io” 无法从java.base模块导出包 - Unable to export a package from java.base module 获取模块 java.base 中所有类的 Class 对象 - Get the Class objects for all classes in the module java.base Eclipse 2021-06:ClassFormatError 可访问:模块 java.base 未“打开 java.lang 模块”以取消命名 - Eclipse 2021-06: ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module Spring 无法在 JDK 17 上启动:模块 java.base 没有“打开 java.lang”到未命名的模块 - Spring Boot can't start on JDK 17 : module java.base does not "opens java.lang" to unnamed module package sun.net.www.protocol.https 在模块 java.base 中声明,不导出它 - package sun.net.www.protocol.https is declared in module java.base, which does not export it 尝试在 Windows 上的 FTPS 中连接时 Talend 作业失败“模块 java.base 不会”打开 sun.security.ssl“到未命名的模块” - Talend jobs when trying to connect in FTPS on Windows fails “module java.base does not ”opens sun.security.ssl“ to unnamed module”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM