简体   繁体   中英

Amazon Coretto 11, Spring Boot and PowerMock - tests failing

I have a java based Spring Boot project that uses PowerMock to mock static methods and contructor invocations where necessary Since upgrading to the latest version of IntelliJ - I need to use a JDK version greater than JDK 8 I moved to Amazon Coretto as I want to deploy my app on the latest support JDK on AWS Elastic Beanstalk When I upgraded and ran my tests, I started hitting issues After following this thread - https://github.com/java-decompiler/jd-gui/issues/187 and using this PowerMockIgnore syntax

@PowerMockIgnore("javax.management.", "com.sun.org.apache.xerces.", "javax.xml.", "org.xml.", "org.w3c.dom.", "com.sun.org.apache.xalan.", "javax.activation.*", "javax.xml.transform.*", "com.sun.org.apache.xalan.*")

I get this error

java.lang.RuntimeException: java.lang.reflect.InaccessibleObjectException: Unable to make protected java.lang.Class jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.lang.String,boolean) throws java.lang.ClassNotFoundException accessible: module java.base does not "opens jdk.internal.loader" to unnamed module @d5ce97f
    at org.powermock.core.classloader.DeferSupportingClassLoader.findResource(DeferSupportingClassLoader.java:154)
    at java.base/java.lang.ClassLoader.findResource(ClassLoader.java:1342)
    at java.base/java.lang.Module.getResourceAsStream(Module.java:1575)
    at kotlin.reflect.jvm.internal.impl.serialization.deserialization.builtins.BuiltInsResourceLoader.loadResource(BuiltInsResourceLoader.java:27)
    at kotlin.reflect.jvm.internal.impl.descriptors.runtime.components.ReflectKotlinClassFinder.findBuiltInsData(ReflectKotlinClassFinder.kt:52)
    at kotlin.reflect.jvm.internal.impl.builtins.jvm.JvmBuiltInsPackageFragmentProvider.findPackage(JvmBuiltInsPackageFragmentProvider.kt:60)

This has had me stumped for days now. Can anyone offer any further suggestions on what I could try

Regards Damien

I could not find a solution to get PowerMock to work with Java 11 so I have removed it from my project

Change your version in Gradle:

testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude group: "org.mockito", module: "mockito-core"
    }
    testCompile("org.mockito:mockito-core:2.23.4")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM