我正在将旧的遗留应用程序从Log4j1.x迁移到2.x,在运行测试用例时出现以下错误。我已经浏览了链接:Powermock - java.lang.IllegalStateException: Failed to transform class,但没有小过门
java.lang.IllegalStateException: Failed to transform class with name com.ABCTest. Reason: java.io.IOException: invalid constant type: 18
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:283)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:192)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:71)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:161)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:48)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:113)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:71)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:526)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:770)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:464)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassType.getClassFile2(CtClassType.java:207)
at javassist.CtClassType.getModifiers(CtClassType.java:370)
at javassist.CtClassType.isInterface(CtClassType.java:358)
at org.powermock.core.transformers.impl.ClassMockTransformer.transformMockClass(ClassMockTransformer.java:39)
at org.powermock.core.transformers.impl.AbstractMainMockTransformer.transform(AbstractMainMockTransformer.java:247)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:264)
... 28 more
下面是maven依赖关系树:
[INFO] +- org.assertj:assertj-core:jar:3.5.1:test
[INFO] +- junit:junit:jar:4.8.2:test
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] | \- org.objenesis:objenesis:jar:2.1:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.5:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.5:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.5:test
[INFO] | | \- org.javassist:javassist:jar:3.20.0-GA:test
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.5:test
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.5:test
[INFO] | \- org.powermock:powermock-api-mockito-common:jar:1.6.5:test
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.5:test
[INFO] +- commons-lang:commons-lang:jar:2.4:compile
[INFO] +- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.mybatis:mybatis-spring:jar:2.0.1:compile
[INFO] +- org.mybatis:mybatis:jar:3.5.1:compile
[INFO] +- com.sybase:jconnect:jar:7.0.7:compile
[INFO] +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] +- jdbc:jcon3:jar:0:compile
[INFO] +- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] | \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] +- javax.jms:jms:jar:1.1:compile
[INFO] +- javax.mail:mail:jar:1.4.5:compile
[INFO] | \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.5.6:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.6:compile
[INFO] +- org.springframework:spring-test:jar:3.2.9.RELEASE:test
[INFO] +- com.ubs.gfs.sbl.halo:HaloAxisWSClient:jar:29.3.1:compile
[INFO] +- antlr:antlr:jar:2.7.7:compile
[INFO] +- com.ibm.mq:com.ibm.mq.allclient:jar:9.1.2.0:compile
[INFO] | +- org.bouncycastle:bcprov-jdk15on:jar:1.60:compile
[INFO] | +- org.bouncycastle:bcpkix-jdk15on:jar:1.60:compile
[INFO] | \- javax.jms:javax.jms-api:jar:2.0.1:compile
[INFO] +- com.ibm.mq:connector:jar:7.0.1.8:compile
[INFO] +- axis:axis:jar:1.4:compile
[INFO] | +- org.apache.axis:axis-jaxrpc:jar:1.4:compile
[INFO] | +- org.apache.axis:axis-saaj:jar:1.4:compile
[INFO] | \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] +- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO] +- com.oracle:ojdbc6:jar:12.1.0.2:compile
[INFO] \- org.apache.poi:poi:jar:3.0.2-FINAL:compile
注意:即使在更新了javassist库之后,我仍然无法使用它。
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
1条答案
按热度按时间inn6fuwd1#
这是由于依赖项冲突造成的。解决依赖项冲突是解决此问题的一种方法,另一种方法是重新排序pom.xml中的
<dependency></dependency>
元素。将powermock依赖项声明移到<dependencies></dependencies>
部分的顶部。这是一个完整的技巧,解决它的正确方法是解决依赖项冲突。要识别这些冲突,您可以使用命令
"mvn dependency:tree"
。下面是我遇到相同问题的应用程序的依赖关系树。请注意,树中有两个“javassist”的依赖关系。在我的例子中,我在项目中添加了很多Maven模块/组件,我在开始工作的powermock依赖项下面添加了该依赖项。