diff --git a/asm/src/main/java/org/objectweb/asm/Type.java b/asm/src/main/java/org/objectweb/asm/Type.java index b46afe72181209d9dc698c97e1ee971c365bea58..07ae832f95673db5ec70546948e83ee6050ca9f9 100644 --- a/asm/src/main/java/org/objectweb/asm/Type.java +++ b/asm/src/main/java/org/objectweb/asm/Type.java @@ -802,12 +802,18 @@ public class Type { case INTERNAL: return opcode + (Opcodes.AALOAD - Opcodes.IALOAD); case METHOD: + case VOID: throw new UnsupportedOperationException(); default: throw new AssertionError(); } } else { switch (sort) { + case VOID: + if (opcode != Opcodes.IRETURN) { + throw new UnsupportedOperationException(); + } + return Opcodes.RETURN; case BOOLEAN: case BYTE: case CHAR: @@ -815,14 +821,18 @@ public class Type { case INT: return opcode; case FLOAT: - return opcode + (Opcodes.FLOAD - Opcodes.ILOAD); + return opcode + (Opcodes.FRETURN - Opcodes.IRETURN); case LONG: - return opcode + (Opcodes.LLOAD - Opcodes.ILOAD); + return opcode + (Opcodes.LRETURN - Opcodes.IRETURN); case DOUBLE: - return opcode + (Opcodes.DLOAD - Opcodes.ILOAD); + return opcode + (Opcodes.DRETURN - Opcodes.IRETURN); case ARRAY: case OBJECT: case INTERNAL: + if (opcode != Opcodes.ILOAD && opcode != Opcodes.ISTORE && opcode != Opcodes.IRETURN) { + throw new UnsupportedOperationException(); + } + return opcode + (Opcodes.ARETURN - Opcodes.IRETURN); case METHOD: throw new UnsupportedOperationException(); default: diff --git a/asm/src/test/java/org/objectweb/asm/TypeTest.java b/asm/src/test/java/org/objectweb/asm/TypeTest.java index 10d8aeb68a50264f01fd66338d688fb0e47d47dc..bd9d050db1ce2e5927e9a09d0990d44d9a7addbe 100644 --- a/asm/src/test/java/org/objectweb/asm/TypeTest.java +++ b/asm/src/test/java/org/objectweb/asm/TypeTest.java @@ -322,6 +322,23 @@ public class TypeTest implements Opcodes { assertEquals(AALOAD, Type.getObjectType("java/lang/Object").getOpcode(IALOAD)); assertEquals(AASTORE, Type.getType("Ljava/lang/Object;").getOpcode(IASTORE)); assertEquals(AASTORE, Type.getObjectType("java/lang/Object").getOpcode(IASTORE)); + assertEquals(AASTORE, Type.getType("[I").getOpcode(IASTORE)); + + assertEquals(RETURN, Type.VOID_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(IRETURN, Type.BOOLEAN_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(IRETURN, Type.BYTE_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(IRETURN, Type.CHAR_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(IRETURN, Type.SHORT_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(IRETURN, Type.INT_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(FRETURN, Type.FLOAT_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(LRETURN, Type.LONG_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(DRETURN, Type.DOUBLE_TYPE.getOpcode(Opcodes.IRETURN)); + assertEquals(ARETURN, Type.getType("Ljava/lang/Object;").getOpcode(Opcodes.IRETURN)); + assertEquals(ARETURN, Type.getObjectType("java/lang/Object").getOpcode(Opcodes.IRETURN)); + assertEquals(ARETURN, Type.getType("Ljava/lang/Object;").getOpcode(Opcodes.IRETURN)); + assertEquals(ARETURN, Type.getObjectType("java/lang/Object").getOpcode(Opcodes.IRETURN)); + assertEquals(ARETURN, Type.getType("[I").getOpcode(Opcodes.IRETURN)); + assertEquals(IADD, Type.BOOLEAN_TYPE.getOpcode(IADD)); assertEquals(IADD, Type.BYTE_TYPE.getOpcode(IADD)); assertEquals(IADD, Type.CHAR_TYPE.getOpcode(IADD)); @@ -332,6 +349,9 @@ public class TypeTest implements Opcodes { assertEquals(DADD, Type.DOUBLE_TYPE.getOpcode(IADD)); Class expectedException = UnsupportedOperationException.class; + assertThrows(expectedException, () -> Type.VOID_TYPE.getOpcode(IADD)); + assertThrows(expectedException, () -> Type.VOID_TYPE.getOpcode(ILOAD)); + assertThrows(expectedException, () -> Type.VOID_TYPE.getOpcode(IALOAD)); assertThrows(expectedException, () -> Type.getType("LI;").getOpcode(IADD)); assertThrows(expectedException, () -> Type.getType("[I").getOpcode(IADD)); assertThrows(expectedException, () -> Type.getObjectType("I").getOpcode(IADD));