PowerMockito 和 CORBA 冲突
PowerMockito and CORBA conflict
我正在尝试使用 PowerMockito 对使用使用 CORBA 的第三方库的项目进行一些测试。我试图通过找到问题的根源来跳过这个异常。我没有成功找到关于这件事的信息。
这是我无法使其工作的最简单的代码:
Java class
@RunWith(PowerMockRunner.class)
public class ORBTest {
@Test
public void initORB() throws Exception {
ORB.init();
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
</project>
Log.error
java.lang.LinkageError: loader constraint violation:
when resolving method "sun.corba.EncapsInputStreamFactory.newEncapsInputStream(Lorg/omg/CORBA/ORB;[BI)Lcom/sun/corba/se/impl/encoding/EncapsInputStream;" the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, com/sun/corba/se/impl/ior/ObjectKeyFactoryImpl, and the class loader (instance of <bootloader>) for resolved class, sun/corba/EncapsInputStreamFactory, have different Class objects for the type /CORBA/ORB;[BI)Lcom/sun/corba/se/impl/encoding/EncapsInputStream; used in the signature
at com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl.create(ObjectKeyFactoryImpl.java:222)
at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.<init>(BootstrapResolverImpl.java:59)
at com.sun.corba.se.spi.resolver.ResolverDefault.makeBootstrapResolver(ResolverDefault.java:75)
at com.sun.corba.se.impl.orb.ORBConfiguratorImpl.initializeNaming(ORBConfiguratorImpl.java:419)
at com.sun.corba.se.impl.orb.ORBConfiguratorImpl.configure(ORBConfiguratorImpl.java:151)
at com.sun.corba.se.impl.orb.ORBImpl.postInit(ORBImpl.java:483)
at com.sun.corba.se.impl.orb.ORBImpl.set_parameters(ORBImpl.java:527)
at com.sun.corba.se.impl.orb.ORBSingleton.getFullORB(ORBSingleton.java:453)
at com.sun.corba.se.impl.orb.ORBSingleton.getORBData(ORBSingleton.java:632)
at com.sun.corba.se.spi.orb.ORB.getLogger(ORB.java:477)
at com.sun.corba.se.spi.orb.ORB.getLogWrapper(ORB.java:523)
at com.sun.corba.se.impl.logging.ORBUtilSystemException.get(ORBUtilSystemException.java:54)
at com.sun.corba.se.spi.orb.ORB.<init>(ORB.java:281)
at com.sun.corba.se.impl.orb.ORBSingleton.<init>(ORBSingleton.java:135)
at org.omg.CORBA.ORB.init(ORB.java:292)
at org.test.test.MockitoTest.test(MockitoTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:89)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access0(PowerMockJUnit47RunnerDelegateImpl.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:202)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:144)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
如果有人能给我一些启发,我将不胜感激,因为您不知道要更改什么才能使这项工作正常进行。
像这样的错误
java.lang.LinkageError: loader constraint violation:
when resolving method ... previously initiated loading for a different type with name...
通常可以通过将 class 或包含方法的包添加到 @PowerMockIgnore
来解决。
对于你的情况,我建议尝试添加到测试
@PowerMockIgnore("org.omg.CORBA.ORB")
我正在尝试使用 PowerMockito 对使用使用 CORBA 的第三方库的项目进行一些测试。我试图通过找到问题的根源来跳过这个异常。我没有成功找到关于这件事的信息。
这是我无法使其工作的最简单的代码:
Java class
@RunWith(PowerMockRunner.class)
public class ORBTest {
@Test
public void initORB() throws Exception {
ORB.init();
}
}
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>1.6.6</version>
</dependency>
</dependencies>
</project>
Log.error
java.lang.LinkageError: loader constraint violation:
when resolving method "sun.corba.EncapsInputStreamFactory.newEncapsInputStream(Lorg/omg/CORBA/ORB;[BI)Lcom/sun/corba/se/impl/encoding/EncapsInputStream;" the class loader (instance of org/powermock/core/classloader/MockClassLoader) of the current class, com/sun/corba/se/impl/ior/ObjectKeyFactoryImpl, and the class loader (instance of <bootloader>) for resolved class, sun/corba/EncapsInputStreamFactory, have different Class objects for the type /CORBA/ORB;[BI)Lcom/sun/corba/se/impl/encoding/EncapsInputStream; used in the signature
at com.sun.corba.se.impl.ior.ObjectKeyFactoryImpl.create(ObjectKeyFactoryImpl.java:222)
at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.<init>(BootstrapResolverImpl.java:59)
at com.sun.corba.se.spi.resolver.ResolverDefault.makeBootstrapResolver(ResolverDefault.java:75)
at com.sun.corba.se.impl.orb.ORBConfiguratorImpl.initializeNaming(ORBConfiguratorImpl.java:419)
at com.sun.corba.se.impl.orb.ORBConfiguratorImpl.configure(ORBConfiguratorImpl.java:151)
at com.sun.corba.se.impl.orb.ORBImpl.postInit(ORBImpl.java:483)
at com.sun.corba.se.impl.orb.ORBImpl.set_parameters(ORBImpl.java:527)
at com.sun.corba.se.impl.orb.ORBSingleton.getFullORB(ORBSingleton.java:453)
at com.sun.corba.se.impl.orb.ORBSingleton.getORBData(ORBSingleton.java:632)
at com.sun.corba.se.spi.orb.ORB.getLogger(ORB.java:477)
at com.sun.corba.se.spi.orb.ORB.getLogWrapper(ORB.java:523)
at com.sun.corba.se.impl.logging.ORBUtilSystemException.get(ORBUtilSystemException.java:54)
at com.sun.corba.se.spi.orb.ORB.<init>(ORB.java:281)
at com.sun.corba.se.impl.orb.ORBSingleton.<init>(ORBSingleton.java:135)
at org.omg.CORBA.ORB.init(ORB.java:292)
at org.test.test.MockitoTest.test(MockitoTest.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:68)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:310)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:89)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:97)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:294)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTestInSuper(PowerMockJUnit47RunnerDelegateImpl.java:131)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.access0(PowerMockJUnit47RunnerDelegateImpl.java:59)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner$TestExecutorStatement.evaluate(PowerMockJUnit47RunnerDelegateImpl.java:147)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.evaluateStatement(PowerMockJUnit47RunnerDelegateImpl.java:107)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl$PowerMockJUnit47MethodRunner.executeTest(PowerMockJUnit47RunnerDelegateImpl.java:82)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:282)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:202)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:144)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:118)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:121)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
如果有人能给我一些启发,我将不胜感激,因为您不知道要更改什么才能使这项工作正常进行。
像这样的错误
java.lang.LinkageError: loader constraint violation: when resolving method ... previously initiated loading for a different type with name...
通常可以通过将 class 或包含方法的包添加到 @PowerMockIgnore
来解决。
对于你的情况,我建议尝试添加到测试
@PowerMockIgnore("org.omg.CORBA.ORB")