Closed GoogleCodeExporter closed 9 years ago
[deleted comment]
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.append("if(value ==
").append(MockGateway.class.getName()).append(".PROCEED) {");
code.append(" $_ = $proceed($$);");
code.append("} else {");
code.append(" $_ =
").append(getCorrectReturnValueType(returnTypeAsCtClass)).append(";");
code.append("}}");
I could reproduce it with pure javassist with a javassist.expr.ExprEditor
instrumented class with
@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();}");
}
Updated code at github.
So javassist produces illegal bytecode due to powermock asking to branch in a
constructor before a super constructor call.
So Powemock must avoid this 'if' in the PowerMockExpressionEditor during that
constructor call.
I opened a Issue at javassist, too: https://issues.jboss.org/browse/JASSIST-228
Original comment by f...@noidea.de
on 18 Jul 2014 at 1:03
[deleted comment]
A MemberMatcher.suppress(MemberMatcher.constructor(MockedClass.class));
before any powermocked mock initialization does not work as a workaround, as
the code of the constructor was already modified.
See updated project on github.
Original comment by f...@noidea.de
on 18 Jul 2014 at 1:28
Updated code to reproduce the issue.
Original comment by f...@noidea.de
on 18 Jul 2014 at 1:48
Attachments:
This might be a JDK bug, see https://bugs.openjdk.java.net/browse/JDK-8051012 .
Original comment by lari.hot...@sagire.fi
on 21 Jul 2014 at 4:05
Original comment by johan.ha...@gmail.com
on 25 Aug 2014 at 6:01
I realize this is 8+ months too late but in case someone else comes looking
here upgrading from java 7u71 to 7u75 fixed the problem for me.
Original comment by hard...@gmail.com
on 27 Feb 2015 at 7:51
Original issue reported on code.google.com by
f...@noidea.de
on 18 Jul 2014 at 11:04Attachments: