[jboss-jira] [JBoss JIRA] (JASSIST-228) Powermock / Javassist creates illegal constructors for JDK 1.7.0u65 and 1.8.0u11 with -target 7.
Florian Burka (JIRA)
issues at jboss.org
Sat Jul 19 03:18:29 EDT 2014
[ https://issues.jboss.org/browse/JASSIST-228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12986247#comment-12986247 ]
Florian Burka edited comment on JASSIST-228 at 7/19/14 3:17 AM:
----------------------------------------------------------------
It seems to boil down to the branching before the super() call for the constructor created inside the ExprEditor in powermocks MainMockTransformer Line 269-273
{code}
code.append("if(value == ").append(MockGateway.class.getName()).append(".PROCEED) {");
code.append(" $_ = $proceed($$);");
code.append("} else {");
code.append(" $_ = ").append(getCorrectReturnValueType(returnTypeAsCtClass)).append(";");
code.append("}}");
{code}
I could reproduce it with pure javassist with a javassist.expr.ExprEditor instrumented class with
{code}
@org.junit.Test
public void testForBadInitCallFromInsideOfABranch() throws Exception
{
CtClass ctClass = ClassPool.getDefault().makeClass("TestForBadInitCallFromInsideOfABranch");
ctClass.addConstructor(CtNewConstructor.make(new CtClass[0], new CtClass[0], "{}", ctClass));
ctClass.instrument(new ExprEditor()
{
@Override
public void edit(ConstructorCall c) throws CannotCompileException
{
//java.lang.VerifyError: Bad <init> method call from inside of a branch
c.replace("if (1 != 2){ super();}");
}
});
final Class<?> clazz = ctClass.toClass();
clazz.getDeclaredConstructors();
}
{code}
Updated code at github.
was (Author: flob):
It seems to boil down to the branching before the super() call for the constructor created inside the ExprEditor in powermocks MainMockTransformer Line 269-273
{code}
code.append("if(value == ").append(MockGateway.class.getName()).append(".PROCEED) {");
code.append(" $_ = $proceed($$);");
code.append("} else {");
code.append(" $_ = ").append(getCorrectReturnValueType(returnTypeAsCtClass)).append(";");
code.append("}}");
{code}
I could reproduce it with pure javassist with a javassist.expr.ExprEditor instrumented class with
{code}
@Override
public void edit(ConstructorCall c) throws CannotCompileException
{
ClassPool classPool = this.clazz.getClassPool();
CtClass constructorType = classPool.get(ConstructorClass.class.getName());
this.clazz.addConstructor(CtNewConstructor.make(new CtClass[] { constructorType}, new CtClass[0], "{super();}", this.clazz));
c.replace("if (1 != 2){ super();}");
}
{code}
Updated code at github.
> Powermock / Javassist creates illegal constructors for JDK 1.7.0u65 and 1.8.0u11 with -target 7.
> ------------------------------------------------------------------------------------------------
>
> Key: JASSIST-228
> URL: https://issues.jboss.org/browse/JASSIST-228
> Project: Javassist
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 3.18.2-GA
> Environment: JDK 1.7.0u65 and 1.8.0u11
> Reporter: Florian Burka
> Assignee: Shigeru Chiba
> Attachments: powermock-javassist-bug.tar.gz
>
>
> Javassist creates illegal constructors for JDK 1.7.0u65 and 1.8.0u11 with -target 7, I have a test that reproduces it at https://github.com/burka/powermock-javassist-bug .
> Somewhere in MainMockTransformer.transform(clazz), I think inside the PowerMockExpressionEditor, the responsible action must have taken place.
> If you remove -target 7 it works for both JDK 1.7.0u65 and 1.8.0u11.
> {code}
> Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.003 sec <<< FAILURE! - in ConstructorTest
> testConstructorManipulationFailure(ConstructorTest) Time elapsed: 0.002 sec <<< ERROR!
> java.lang.VerifyError: Bad <init> method call from inside of a branch
> Exception Details:
> Location:
> MockedClass.<init>()V @32: invokespecial
> Reason:
> Error exists in the bytecode
> Bytecode:
> 0000000: 2a4c 120f b800 1503 bd00 0d12 16b8 001a
> 0000010: b800 204e 2db2 0024 a500 0e2a 01c0 0026
> 0000020: b700 29a7 0009 2bb7 002b 0157 b1
> Stackmap Table:
> full_frame(@38,{UninitializedThis,UninitializedThis,Top,Object[#13]},{})
> full_frame(@44,{Object[#2],Object[#2],Top,Object[#13]},{})
> at java.lang.Class.getDeclaredConstructors0(Native Method)
> at java.lang.Class.privateGetDeclaredConstructors(Class.java:2658)
> at java.lang.Class.getDeclaredConstructors(Class.java:2007)
> at ConstructorTest.testConstructorManipulationFailure(ConstructorTest.java:13)
> {code}
> I created a powermock ticket at
> https://code.google.com/p/powermock/issues/detail?id=505
--
This message was sent by Atlassian JIRA
(v6.2.6#6264)
More information about the jboss-jira
mailing list