diff --git a/src/main/java/org/jboss/jandex/Indexer.java b/src/main/java/org/jboss/jandex/Indexer.java index 95438432..e46461dc 100644 --- a/src/main/java/org/jboss/jandex/Indexer.java +++ b/src/main/java/org/jboss/jandex/Indexer.java @@ -534,10 +534,12 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati } case 0x10: // CLASS_EXTENDS { - if (!(target instanceof ClassInfo)) { - throw new IllegalStateException("Class extends type annotation appeared on a non class target"); + int position = data.readUnsignedShort(); + + // Skip invalid usage (observed bad bytecode on method attributes) + if (target instanceof ClassInfo) { + typeTarget = new ClassExtendsTypeTarget((ClassInfo)target, position); } - typeTarget = new ClassExtendsTypeTarget((ClassInfo)target, data.readUnsignedShort()); break; } case 0x11: // CLASS_TYPE_PARAMETER_BOUND @@ -553,18 +555,18 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati break; case 0x16: // METHOD_FORMAL_PARAMETER { - if (!(target instanceof MethodInfo)) { - throw new IllegalStateException("Method parameter type annotation appeared on a non-method target"); + int position = data.readUnsignedByte(); + if (target instanceof MethodInfo) { + typeTarget = new MethodParameterTypeTarget((MethodInfo)target, position); } - typeTarget = new MethodParameterTypeTarget((MethodInfo)target, data.readUnsignedByte()); break; } case 0x17: // THROWS { - if (!(target instanceof MethodInfo)) { - throw new IllegalStateException("Throws type annotation appeared on a non-method target"); + int position = data.readUnsignedShort(); + if (target instanceof MethodInfo) { + typeTarget = new ThrowsTypeTarget((MethodInfo) target, position); } - typeTarget = new ThrowsTypeTarget((MethodInfo) target, data.readUnsignedShort()); break; } // Skip code attribute values, which shouldn't be present @@ -595,6 +597,10 @@ private TypeAnnotationState processTypeAnnotation(DataInputStream data, Annotati } if (typeTarget == null) { + skipTargetPath(data); + // eat + // TODO - introduce an allocation free annotation skip + processAnnotation(data, null); return null; } @@ -1055,6 +1061,11 @@ private ArrayList processTargetPath(DataInputStream data, BooleanHo return elements; } + private void skipTargetPath(DataInputStream data) throws IOException { + int numElements = data.readUnsignedByte(); + skipFully(data, numElements * 2); + } + private void processExceptions(DataInputStream data, MethodInfo target) throws IOException { int numExceptions = data.readUnsignedShort();