使用powermock模拟方法内new对象
下面是异常信息
java.lang.IllegalStateException: Failed to transform class with name com.linx.vm.service.impl.ChangeVmCdImpl. Reason: java.io.IOException: invalid constant type: 18
at org.powermock.core.classloader.javassist.JavassistMockClassLoader.defineAndTransformClass(JavassistMockClassLoader.java:119)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:174)
at org.powermock.core.classloader.MockClassLoader.loadClassByThisClassLoader(MockClassLoader.java:102)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:147)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:98)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:439)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:420)
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.Class.createAnnotationData(Class.java:3521)
at java.lang.Class.annotationData(Class.java:3510)
at java.lang.Class.getAnnotation(Class.java:3415)
at org.junit.internal.MethodSorter.getDeclaredMethods(MethodSorter.java:52)
at org.junit.internal.runners.TestClass.getAnnotatedMethods(TestClass.java:45)
at org.junit.internal.runners.MethodValidator.validateTestMethods(MethodValidator.java:71)
at org.junit.internal.runners.MethodValidator.validateStaticMethods(MethodValidator.java:44)
at org.junit.internal.runners.MethodValidator.validateMethodsForDefaultRunner(MethodValidator.java:50)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.validate(PowerMockJUnit44RunnerDelegateImpl.java:124)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.<init>(PowerMockJUnit44RunnerDelegateImpl.java:86)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl.<init>(PowerMockJUnit47RunnerDelegateImpl.java:42)
at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl.<init>(PowerMockJUnit49RunnerDelegateImpl.java:25)
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.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:165)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:47)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:107)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:69)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:36)
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:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassType.getClassFile2(CtClassType.java:203)
at javassist.CtClassType.subtypeOf(CtClassType.java:303)
at javassist.bytecode.stackmap.TypeData$TypeName.update(TypeData.java:274)
at javassist.bytecode.stackmap.TypeData$TypeName.setType(TypeData.java:203)
at javassist.bytecode.stackmap.TypeData.setType(TypeData.java:46)
at javassist.bytecode.stackmap.Tracer.checkParamTypes(Tracer.java:908)
at javassist.bytecode.stackmap.Tracer.checkParamTypes(Tracer.java:898)
at javassist.bytecode.stackmap.Tracer.doInvokeMethod(Tracer.java:813)
at javassist.bytecode.stackmap.Tracer.doOpcode148_201(Tracer.java:615)
at javassist.bytecode.stackmap.Tracer.doOpcode(Tracer.java:101)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:161)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:171)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:120)
at javassist.bytecode.stackmap.MapMaker.make(MapMaker.java:96)
at javassist.bytecode.MethodInfo.rebuildStackMap(MethodInfo.java:404)
at javassist.bytecode.MethodInfo.rebuildStackMapIf6(MethodInfo.java:389)
at javassist.expr.ExprEditor.doit(ExprEditor.java:112)
at javassist.CtClassType.instrument(CtClassType.java:1374)
at org.powermock.core.transformers.javassist.InstrumentMockTransformer.transform(InstrumentMockTransformer.java:41)
at org.powermock.core.transformers.javassist.AbstractJavaAssistMockTransformer.transform(AbstractJavaAssistMockTransformer.java:40)
at org.powermock.core.transformers.support.DefaultMockTransformerChain.transform(DefaultMockTransformerChain.java:43)
at org.powermock.core.classloader.MockClassLoader.transformClass(MockClassLoader.java:184)
at org.powermock.core.classloader.javassist.JavassistMockClassLoader.defineAndTransformClass(JavassistMockClassLoader.java:102)
... 55 more
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
at javassist.bytecode.ConstPool.read(ConstPool.java:970)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:716)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:103)
at javassist.CtClassType.getClassFile2(CtClassType.java:190)
... 139 more
相似问题