Use powermock to report an error Java Lang. linkageerror: load constraint violation
Error reporting information (limited to deletion of space): analysis and solution extension
Error reporting information (limited to deletion of space):
java.lang.LinkageError: Loading constraint violation: loaders“org/powermock/core/classloader/javassist/JavassistMockClassLoader@47ab16ce”先前已启动由装入器“com/ibm/oti/vm/BootstrapClassLoader@ba626924”定义的名为“javax/security/auth/x500/X500Principal”的另一种类型的装入
\tat java.lang.ClassLoader.defineClassImpl(Native Method)
\tat java.lang.ClassLoader.defineClass(ClassLoader.java:346)
\tat org.powermock.core.classloader.javassist.JavassistMockClassLoader.loadUnmockedClass(JavassistMockClassLoader.java:90)
\tat org.powermock.core.classloader.MockClassLoader.loadClassByThisClassLoader(MockClassLoader.java:104)
\tat 、ock.core.MockInvocation.init(MockInvocation.java:31)
\tat org.powermock.core.MockInvocation.<init>(MockInvocation.java:22)
\tat org.powermock.core.MockGateway.doMethodCall(MockGateway.java:155)
\tat org.powermock.core.MockGateway.methodCall(MockGateway.java:138)
analysis
java.Lang.linkageerror this exception is often encountered in applications using multiple classloaders
the reason for this error is the class conflict caused by the cross use of class classes with the same qualified name after being loaded by multiple different classloaders. Classes with the same qualified name belong to different class instances in different classloaders. When loading a class, the JVM needs to load all imported classes. In this case, if there is a class with the same qualified name in the custom classloader as that in the parent classloader, Java. Net will be thrown Lang.LinkageError.
from the error message, you can see that the javax/security/auth/X500/X500 principal class is loaded by the classloader and bootstrapclassloader customized by powermock at the same time.
Solution:
Use @powermockignore to make javassistmockclassloader ignore the loading of javax/security/auth/X500/X500 principal:
@PowerMockIgnore({"javax.security.*"})
Read More:
- [Solved] No validator could be found for constraint ‘javax.validation.constraints.NotBlank’ validating type ‘java.lang.String’
- [Solved] nacos Startup Error: nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error
- JUnit test classes error: java.lang.IllegalStateException: Failed to load ApplicationContext
- [Solved] Java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.util.List
- [Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)
- [Solved] JAVA Project Import jstl Error: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator
- [Solved] IDEA springboot Startup Error: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path
- [Solved] Java 9 reflection error: java.lang.reflect.InaccessibleObjectException
- [Solved] JAVA OpenCV Startup Error: java.lang.UnsatisfiedLinkError
- Java.lang.exceptionininitializererror [How to Fix]
- Java error: java.lang.NoSuchMethodError
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] Hbase-shell 2.x Error: Unhandled Java exception: java.lang.IncompatibleClassChangeError: Found class jline.Terminal…
- [Solved] java: Internal error in the mapping processor: java.lang.NullPointerException
- [Solved] JAVA fx Error: java.lang.instrument ASSERTION FAILED ***: “!errorOutstanding“ with message transform
- JAVA error: java.lang.OutOfMemoryError:GC overhead limit exceeded
- java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x590
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- [Solved] JAVA Error: Error occurred during initialization of boot layer java.lang.module.FindException