英文:
JAVA 17 Junit test cases failing with java.lang.reflect.InaccessibleObjectException
问题
java版本:17 mockito版本:5.3.0
由于我正在升级到java 17,junit测试用例失败的原因是:
> 由于模块java.base未“opens java.lang”给未命名模块@38cccef,无法使受保护的最终java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError可访问。
请建议一些解决方案,因为我不能使用以下解决方案:
1. —add-opens java.base/java.lang=ALL-UNNAMED
或者
2. --illegal-access=permit (在java 17中已删除)
我期望通过在pom.xml中添加新的依赖项或者使用不同版本的mockito来解决这个问题,同时尽量减少代码修改。
英文:
java version:17 mockito version:5.3.0
As I am upgrading to java 17, junit test cases are failing with reason:
> Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @38cccef
Please suggest some solution as I CANNOT use solutions:
- —add-opens java.base/java.lang=ALL-UNNAMED
or - --illegal-access=permit (removed in java 17)
I am expecting to solve this problem by adding any new dependency in pom.xml or different version of mockito. with minimal code change.
答案1
得分: 2
添加到pom文件中的部分翻译如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</build>
英文:
add this to pom:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<argLine>--add-opens java.base/java.lang=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</build>
答案2
得分: 0
Follow the instructions in the mockito release notes under '5.0.0' here. Essentially, switch the mockmaker implementation.
或者降级回到 JDK11。
英文:
Follow the instructions in the mockito release notes under '5.0.0' here. Essentially, switch the mockmaker implementation.
That, or downgrade back to JDK11.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论