Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Don't unboxJava if it's not a JavaObjectWrapper.
This fixes a ClassCastException leaking to the HLL when we call what() on a
TypeObject.
  • Loading branch information
peschwa committed Apr 24, 2015
1 parent 4b13834 commit 9e2b706
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/runtime/BootJavaInterop.java
Expand Up @@ -19,6 +19,7 @@
import java.util.Map;

import org.perl6.nqp.sixmodel.STable;
import org.perl6.nqp.sixmodel.TypeObject;
import org.perl6.nqp.sixmodel.SixModelObject;
import org.perl6.nqp.sixmodel.StorageSpec;
import org.perl6.nqp.sixmodel.reprs.JavaObjectWrapper;
Expand Down Expand Up @@ -725,10 +726,18 @@ else if(what.getComponentType() != null) {
Type.getMethodDescriptor(Type.getType(Object[].class), TYPE_SMO, TYPE_TC, Type.getType(Class.class)));
}
else {
Label isntWrapped = new Label(), done = new Label();
mv.visitInsn(Opcodes.DUP);
mv.visitVarInsn(Opcodes.ALOAD, c.tcLoc);
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TYPE_OPS.getInternalName(), "decont", Type.getMethodDescriptor(TYPE_SMO, TYPE_SMO, TYPE_TC));
mv.visitTypeInsn(Opcodes.INSTANCEOF, Type.getType(JavaObjectWrapper.class).getInternalName());
mv.visitJumpInsn(Opcodes.IFEQ, isntWrapped);
mv.visitVarInsn(Opcodes.ALOAD, c.tcLoc);
// XXX: the secondary decont is a bit awkward, but storing to the stack doesn't seem to work out
mv.visitMethodInsn(Opcodes.INVOKESTATIC, TYPE_OPS.getInternalName(), "decont", Type.getMethodDescriptor(TYPE_SMO, TYPE_SMO, TYPE_TC));
mv.visitMethodInsn(Opcodes.INVOKESTATIC, "org/perl6/nqp/runtime/BootJavaInterop$RuntimeSupport", "unboxJava", Type.getMethodDescriptor(TYPE_OBJ, TYPE_SMO));
mv.visitTypeInsn(Opcodes.CHECKCAST, Type.getInternalName(what));
mv.visitLabel(isntWrapped);
}
}

Expand Down

0 comments on commit 9e2b706

Please sign in to comment.