From 434c3c633cfe52529152bef49e1b5558cc641bd8 Mon Sep 17 00:00:00 2001 From: Eric Bruneton Date: Sat, 30 Jun 2018 10:29:37 +0200 Subject: [PATCH 1/3] Add failing test showing the regression. --- .../java/org/objectweb/asm/commons/GeneratorAdapterTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java b/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java index 09968813..46183a6c 100644 --- a/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java +++ b/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java @@ -407,6 +407,9 @@ public class GeneratorAdapterTest { assertEquals("I2C", new Generator().cast(Type.INT_TYPE, Type.CHAR_TYPE)); assertEquals("I2S", new Generator().cast(Type.INT_TYPE, Type.SHORT_TYPE)); + assertEquals("", new Generator().cast(Type.BYTE_TYPE, Type.INT_TYPE)); + assertEquals("", new Generator().cast(Type.SHORT_TYPE, Type.INT_TYPE)); + assertThrows( IllegalArgumentException.class, () -> new Generator().cast(Type.INT_TYPE, Type.VOID_TYPE)); } -- GitLab From 7d045e01cdadad95d62534ef92cb0eca2eec1a17 Mon Sep 17 00:00:00 2001 From: Eric Bruneton Date: Sat, 30 Jun 2018 10:41:08 +0200 Subject: [PATCH 2/3] Fix the regression, make previously added tests pass. --- .../java/org/objectweb/asm/commons/GeneratorAdapter.java | 8 ++++++-- .../org/objectweb/asm/commons/GeneratorAdapterTest.java | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java b/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java index 44227784..aad21988 100644 --- a/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java +++ b/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java @@ -741,6 +741,12 @@ public class GeneratorAdapter extends LocalVariablesSorter { */ public void cast(final Type from, final Type to) { if (from != to) { + if (from.getSort() < Type.BOOLEAN + || from.getSort() > Type.DOUBLE + || to.getSort() < Type.BOOLEAN + || to.getSort() > Type.DOUBLE) { + throw new IllegalArgumentException(); + } if (from == Type.DOUBLE_TYPE) { if (to == Type.FLOAT_TYPE) { mv.visitInsn(Opcodes.D2F); @@ -781,8 +787,6 @@ public class GeneratorAdapter extends LocalVariablesSorter { mv.visitInsn(Opcodes.I2L); } else if (to == Type.SHORT_TYPE) { mv.visitInsn(Opcodes.I2S); - } else { - throw new IllegalArgumentException(); } } } diff --git a/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java b/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java index 46183a6c..654c75e9 100644 --- a/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java +++ b/asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java @@ -410,6 +410,8 @@ public class GeneratorAdapterTest { assertEquals("", new Generator().cast(Type.BYTE_TYPE, Type.INT_TYPE)); assertEquals("", new Generator().cast(Type.SHORT_TYPE, Type.INT_TYPE)); + assertThrows( + IllegalArgumentException.class, () -> new Generator().cast(Type.VOID_TYPE, Type.INT_TYPE)); assertThrows( IllegalArgumentException.class, () -> new Generator().cast(Type.INT_TYPE, Type.VOID_TYPE)); } -- GitLab From bb3bdde4c41a7ceb166c81d13a29edcf914fa7fb Mon Sep 17 00:00:00 2001 From: Eric Bruneton Date: Tue, 3 Jul 2018 20:13:28 +0200 Subject: [PATCH 3/3] Address the code review comments. --- .../main/java/org/objectweb/asm/commons/GeneratorAdapter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java b/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java index aad21988..b8adb4cc 100644 --- a/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java +++ b/asm-commons/src/main/java/org/objectweb/asm/commons/GeneratorAdapter.java @@ -745,7 +745,7 @@ public class GeneratorAdapter extends LocalVariablesSorter { || from.getSort() > Type.DOUBLE || to.getSort() < Type.BOOLEAN || to.getSort() > Type.DOUBLE) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("Cannot cast from " + from + " to " + to); } if (from == Type.DOUBLE_TYPE) { if (to == Type.FLOAT_TYPE) { -- GitLab