From 9577935023c88b56d67a7cbcd5b9786031895abd Mon Sep 17 00:00:00 2001 From: forax Date: Sun, 7 Jan 2018 00:11:47 +0100 Subject: [PATCH 1/3] add missing tests for Type.getOpcode() --- .../test/java/org/objectweb/asm/TypeTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/asm/src/test/java/org/objectweb/asm/TypeTest.java b/asm/src/test/java/org/objectweb/asm/TypeTest.java index 10d8aeb68..e8474a664 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)); -- GitLab From 357014aa310b87b3c127b9013f305f6b6ef472c0 Mon Sep 17 00:00:00 2001 From: forax Date: Sun, 7 Jan 2018 00:12:32 +0100 Subject: [PATCH 2/3] fix Type.getOpcode() close #317805 --- asm/src/main/java/org/objectweb/asm/Type.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/asm/src/main/java/org/objectweb/asm/Type.java b/asm/src/main/java/org/objectweb/asm/Type.java index b46afe721..679ac908c 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: -- GitLab From 2530c4b4ed9114fe4aefb7e97d86f7b66c7619b8 Mon Sep 17 00:00:00 2001 From: forax Date: Sun, 7 Jan 2018 00:18:24 +0100 Subject: [PATCH 3/3] forget again to run google-format, it doesn't seem to run when just running the test in Gradle --- asm/src/main/java/org/objectweb/asm/Type.java | 2 +- asm/src/test/java/org/objectweb/asm/TypeTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/asm/src/main/java/org/objectweb/asm/Type.java b/asm/src/main/java/org/objectweb/asm/Type.java index 679ac908c..07ae832f9 100644 --- a/asm/src/main/java/org/objectweb/asm/Type.java +++ b/asm/src/main/java/org/objectweb/asm/Type.java @@ -830,7 +830,7 @@ public class Type { case OBJECT: case INTERNAL: if (opcode != Opcodes.ILOAD && opcode != Opcodes.ISTORE && opcode != Opcodes.IRETURN) { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } return opcode + (Opcodes.ARETURN - Opcodes.IRETURN); case METHOD: diff --git a/asm/src/test/java/org/objectweb/asm/TypeTest.java b/asm/src/test/java/org/objectweb/asm/TypeTest.java index e8474a664..bd9d050db 100644 --- a/asm/src/test/java/org/objectweb/asm/TypeTest.java +++ b/asm/src/test/java/org/objectweb/asm/TypeTest.java @@ -323,7 +323,7 @@ public class TypeTest implements Opcodes { 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)); @@ -338,7 +338,7 @@ public class TypeTest implements Opcodes { 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)); -- GitLab