Skip to content

Commit

Permalink
Fixed method references to constructors causing VerifyError on Android
Browse files Browse the repository at this point in the history
Android doesn't like a non-empty stack when we return from a method

Fixes #67
  • Loading branch information
luontola committed Sep 6, 2015
1 parent ac4a374 commit b8c21e4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ optimizations to that mechanism may break Retrolambda.
Version History
---------------

### Upcoming

- Fixed method references to constructors causing VerifyError on Android
([Issue #67](https://github.com/orfjackal/retrolambda/issues/67))

### Retrolambda 2.0.5 (2015-07-19)

- Support for lambdas with marker interfaces
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,15 @@ public void visitMethodInsn(int opcode, String owner, String name, String desc,
&& accessMethod.getTag() == H_INVOKESTATIC) {
// The impl is a private constructor which is called through an access method.
// XXX: The current method already did NEW an instance, but we won't use it because
// the access method will also instantiate it, so we could remove the unused
// instance from stack using the following code, but this is not strictly necessary
// because ARETURN is allowed to leave behind a non-empty stack. We could improve
// this backporter so that it would remove the unnecessary "NEW, DUP" instructions,
// but that would be complicated.
if (false) {
super.visitVarInsn(ASTORE, 1);
super.visitInsn(POP);
super.visitInsn(POP);
super.visitVarInsn(ALOAD, 1);
}
// the access method will also instantiate it.
// - The JVM would be OK with a non-empty stack on ARETURN, but it causes a VerifyError
// on Android, so here we remove the unused instance from the stack.
// - We could improve this backporter so that it would remove the unnecessary
// "NEW, DUP" instructions, but that would be complicated.
super.visitVarInsn(ASTORE, 1);
super.visitInsn(POP);
super.visitInsn(POP);
super.visitVarInsn(ALOAD, 1);
}
} else {
super.visitMethodInsn(opcode, owner, name, desc, itf);
Expand Down

0 comments on commit b8c21e4

Please sign in to comment.