ASM improperly processing MethodParameters in Java 1.7 class
MethodParameters should only be processed in Java 8 or higher class files.
Background: There is an OpenJPA tool (http://openjpa.apache.org/) that generates class files. Unfortunately, when it generates class files, it includes MethodParameters. While, they really shouldn't do that for Java 1.7 class files, the generated classes are still valid. They just contain extra junk (MethodParameters) which should be ignored in Java 7 classes.
We've tested this on ASM 5 and up, and unfortunately, ASM processes the MethodParameters which results in:
ExtendedMessage: Corrupt classjava.lang.ArrayIndexOutOfBoundsException
at org.objectweb.asm.ClassReader.a(Unknown Source)
at org.objectweb.asm.ClassReader.readUTF8(Unknown Source)
at org.objectweb.asm.ClassReader.b(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
at org.objectweb.asm.ClassReader.accept(Unknown Source)
This is an easy fix in ClassReader.java. Simply don't process MethodParameters when the class version is less than Java 8.
Add variables to ClassReader.java:
private final int classFileVersion;
private final boolean readMethodParameters;
In the ClassReader constructor, add this:
this.classFileVersion = readShort(classFileOffset + 6);
this.readMethodParameters = (classFileVersion > Opcodes.V1_7);
In readMethod(ClassVisitor, Context, int) method:
} else if (readMethodParameters && Constants.METHOD_PARAMETERS.equals(attributeName)) {
methodParametersOffset = currentOffset;