summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Bruneton <ebruneton@free.fr>2023-01-21 10:24:38 +0000
committerEric Bruneton <ebruneton@free.fr>2023-01-21 10:24:38 +0000
commit443339a964352dcec4dd3915de8f13188920d3ac (patch)
tree1b67b9d79f6bc0e2c1e3865c33c8310d26b840fe
parent5029e4250d8819ca13674b4d85aa13d84428eede (diff)
parent1865bc9cb34ecc566a3ade2698b5317754da3b5a (diff)
downloadow2-asm-443339a964352dcec4dd3915de8f13188920d3ac.tar.gz
Merge branch 'feature/IllegalArgumentErrorHandling' into 'master'
Feature/illegal argument error handling See merge request asm/asm!370
-rw-r--r--asm-util/src/main/java/org/objectweb/asm/util/CheckMethodAdapter.java6
-rw-r--r--asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java6
-rw-r--r--asm/src/main/java/org/objectweb/asm/Frame.java5
3 files changed, 12 insertions, 5 deletions
diff --git a/asm-util/src/main/java/org/objectweb/asm/util/CheckMethodAdapter.java b/asm-util/src/main/java/org/objectweb/asm/util/CheckMethodAdapter.java
index b6759073..339af5d1 100644
--- a/asm-util/src/main/java/org/objectweb/asm/util/CheckMethodAdapter.java
+++ b/asm-util/src/main/java/org/objectweb/asm/util/CheckMethodAdapter.java
@@ -1101,9 +1101,13 @@ public class CheckMethodAdapter extends MethodVisitor {
* @param method the expected visit method.
*/
private static void checkOpcodeMethod(final int opcode, final Method method) {
- if (opcode < Opcodes.NOP || opcode > Opcodes.IFNONNULL || OPCODE_METHODS[opcode] != method) {
+ if (opcode < Opcodes.NOP || opcode > Opcodes.IFNONNULL) {
throw new IllegalArgumentException("Invalid opcode: " + opcode);
}
+ if (OPCODE_METHODS[opcode] != method) {
+ throw new IllegalArgumentException(
+ "Invalid combination of opcode and method: " + opcode + ", " + method);
+ }
}
/**
diff --git a/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java b/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java
index 6652d29b..817d3d65 100644
--- a/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java
+++ b/asm-util/src/test/java/org/objectweb/asm/util/CheckMethodAdapterTest.java
@@ -434,7 +434,8 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
Executable visitMethodInsn = () -> checkMethodAdapter.visitMethodInsn(42, "o", "m", "()V");
Exception exception = assertThrows(IllegalArgumentException.class, visitMethodInsn);
- assertEquals("Invalid opcode: 42", exception.getMessage());
+ assertEquals(
+ "Invalid combination of opcode and method: 42, VISIT_METHOD_INSN", exception.getMessage());
}
@Test
@@ -445,7 +446,8 @@ class CheckMethodAdapterTest extends AsmTest implements Opcodes {
() -> checkMethodAdapter.visitMethodInsn(42, "o", "m", "()V", false);
Exception exception = assertThrows(IllegalArgumentException.class, visitMethodInsn);
- assertEquals("Invalid opcode: 42", exception.getMessage());
+ assertEquals(
+ "Invalid combination of opcode and method: 42, VISIT_METHOD_INSN", exception.getMessage());
}
@Test
diff --git a/asm/src/main/java/org/objectweb/asm/Frame.java b/asm/src/main/java/org/objectweb/asm/Frame.java
index 07f256e5..89195006 100644
--- a/asm/src/main/java/org/objectweb/asm/Frame.java
+++ b/asm/src/main/java/org/objectweb/asm/Frame.java
@@ -367,11 +367,12 @@ class Frame {
typeValue = REFERENCE_KIND | symbolTable.addType(internalName);
break;
default:
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException(
+ "Invalid descriptor fragment: " + buffer.substring(elementDescriptorOffset));
}
return ((elementDescriptorOffset - offset) << DIM_SHIFT) | typeValue;
default:
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Invalid descriptor: " + buffer.substring(offset));
}
}