junit - Powermock - java.lang.IllegalStateException: Failed to transform class -
description:
i trying test static method class. using powermock (1.6.2) + mockito (1.10.19) mocking along junit4 (4.12) & java8.
issue:
getting error: "failed transform class name com.gs.ops.domain.staticclass reason: java.io.ioexception: invalid constant type: 18"
solutions tried:
googled threads issue on powermock - mockito & java-8
excluded java assist powermock , added java assist 3.19.0-ga
tried different versions of powermock (1.5.4, 1.6.2...)
below exception stack trace:
java.lang.illegalstateexception: failed transform class name com.staticclass. reason: java.io.ioexception: invalid constant type: 18 @ org.powermock.core.classloader.mockclassloader.loadmockclass(mockclassloader.java:266) @ org.powermock.core.classloader.mockclassloader.loadmodifiedclass(mockclassloader.java:180) @ org.powermock.core.classloader.defersupportingclassloader.loadclass(defersupportingclassloader.java:68) @ java.lang.classloader.loadclass(classloader.java:357) @ java.lang.class.forname0(native method) @ java.lang.class.forname(class.java:340) @ org.powermock.modules.junit4.common.internal.impl.junit4testsuitechunkerimpl.createdelegatorfromclassloader(junit4testsuitechunkerimpl.java:145) @ org.powermock.modules.junit4.common.internal.impl.junit4testsuitechunkerimpl.createdelegatorfromclassloader(junit4testsuitechunkerimpl.java:40) @ org.powermock.tests.utils.impl.abstracttestsuitechunkerimpl.createtestdelegators(abstracttestsuitechunkerimpl.java:244) @ org.powermock.modules.junit4.common.internal.impl.junit4testsuitechunkerimpl.<init>(junit4testsuitechunkerimpl.java:61) @ org.powermock.modules.junit4.common.internal.impl.abstractcommonpowermockrunner.<init>(abstractcommonpowermockrunner.java:32) @ org.powermock.modules.junit4.powermockrunner.<init>(powermockrunner.java:34) @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:408) @ org.junit.internal.builders.annotatedbuilder.buildrunner(annotatedbuilder.java:104) @ org.junit.internal.builders.annotatedbuilder.runnerforclass(annotatedbuilder.java:86) @ org.junit.runners.model.runnerbuilder.saferunnerforclass(runnerbuilder.java:59) @ org.junit.internal.builders.alldefaultpossibilitiesbuilder.runnerforclass(alldefaultpossibilitiesbuilder.java:26) @ org.junit.runners.model.runnerbuilder.saferunnerforclass(runnerbuilder.java:59) @ org.junit.internal.requests.classrequest.getrunner(classrequest.java:33) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:67) caused by: java.lang.runtimeexception: java.io.ioexception: invalid constant type: 18 @ javassist.ctclasstype.getclassfile2(ctclasstype.java:203) @ javassist.compiler.memberresolver.lookupmethod(memberresolver.java:110) @ javassist.compiler.memberresolver.lookupmethod(memberresolver.java:96) @ javassist.compiler.typechecker.atmethodcallcore(typechecker.java:704) @ javassist.expr.newexpr$proceedfornew.setreturntype(newexpr.java:243) @ javassist.compiler.jvsttypechecker.atcallexpr(jvsttypechecker.java:146) @ javassist.compiler.ast.callexpr.accept(callexpr.java:45) @ javassist.compiler.typechecker.atvariableassign(typechecker.java:248) @ javassist.compiler.typechecker.atassignexpr(typechecker.java:217) @ javassist.compiler.ast.assignexpr.accept(assignexpr.java:38) @ javassist.compiler.codegen.dotypecheck(codegen.java:241) @ javassist.compiler.codegen.atstmnt(codegen.java:329) @ javassist.compiler.ast.stmnt.accept(stmnt.java:49) @ javassist.compiler.codegen.atstmnt(codegen.java:350) @ javassist.compiler.ast.stmnt.accept(stmnt.java:49) @ javassist.compiler.codegen.atifstmnt(codegen.java:404) @ javassist.compiler.codegen.atstmnt(codegen.java:354) @ javassist.compiler.ast.stmnt.accept(stmnt.java:49) @ javassist.compiler.javac.compilestmnt(javac.java:568) @ javassist.expr.newexpr.replace(newexpr.java:206) @ org.powermock.core.transformers.impl.mainmocktransformer$powermockexpressioneditor.edit(mainmocktransformer.java:418) @ javassist.expr.expreditor.loopbody(expreditor.java:211) @ javassist.expr.expreditor.doit(expreditor.java:90) @ javassist.ctclasstype.instrument(ctclasstype.java:1374) @ org.powermock.core.transformers.impl.mainmocktransformer.transform(mainmocktransformer.java:74) @ org.powermock.core.classloader.mockclassloader.loadmockclass(mockclassloader.java:251) ... 24 more caused by: java.io.ioexception: invalid constant type: 18 @ javassist.bytecode.constpool.readone(constpool.java:1090) @ javassist.bytecode.constpool.read(constpool.java:1033) @ javassist.bytecode.constpool.<init>(constpool.java:149) @ javassist.bytecode.classfile.read(classfile.java:737) @ javassist.bytecode.classfile.<init>(classfile.java:108) @ javassist.ctclasstype.getclassfile2(ctclasstype.java:190) ... 49 more
pom file:
<dependency> <groupid>org.powermock</groupid> <artifactid>powermock-api-mockito</artifactid> <version>1.6.2</version> <scope>test</scope> </dependency> <dependency> <groupid>org.powermock</groupid> <artifactid>powermock-module-junit4</artifactid> <version>1.6.2</version> <exclusions> <exclusion> <groupid>org.junit</groupid> <artifactid>junit</artifactid> </exclusion> <exclusion> <groupid>org.powermock</groupid> <artifactid>powermock-core</artifactid> </exclusion> <exclusion> <groupid>org.powermock</groupid> <artifactid>powermock-reflect</artifactid> </exclusion> </exclusions> <scope>test</scope> </dependency> <dependency> <groupid>org.javassist</groupid> <artifactid>javassist</artifactid> <version>3.19.0-ga</version> </dependency>
powermock 1.6.3 uses javassist 3.15.2-ga not support types. using 3.18.2-ga javassist worked me. may want override dependency in project.
<dependency> <groupid>org.javassist</groupid> <artifactid>javassist</artifactid> <version>3.18.2-ga</version> </dependency>
you may face problem solution lies here mockito + powermock linkageerror while mocking system class
hope helps.
Comments
Post a Comment