MethodWriter generates invalid RuntimeInvisibleParameterAnnotations for enum constructors
If a parameter of an enum constructor is annotated and the constructor is
instrumented using ASM, the produced class file causes javac to crash. The
following stacktrace is produced:
java.lang.NullPointerException
at
com.sun.tools.javac.jvm.ClassReader.attachParameterAnnotations(ClassReader.java:898)
at com.sun.tools.javac.jvm.ClassReader.readMemberAttr(ClassReader.java:789)
at com.sun.tools.javac.jvm.ClassReader.readMemberAttrs(ClassReader.java:834)
at com.sun.tools.javac.jvm.ClassReader.readMethod(ClassReader.java:1235)
...
The reason for that is following: javac generates two hidden parameters passed
to the java.lang.Enum constructor, which should not be included in the
RuntimeInvisibleParameterAnnotations value. For example, if an enum constructor
has one actual parameter which is annotated, javac generates
RuntimeInvisibleParameterAnnotations with num_parameters=1, while ASM generates
the same attribute with num_parameters=3. The two hidden parameters should not
be taken into account when calculating the size of the panns/ipanns array in
MethodWriter.visitParameterAnnotation().
The problem was reproduced in ASM 2.1 but as far as I can see it's not fixed in
any later version.
See http://jetbrains.net/jira/browse/IDEADEV-19874 for the original bug report
which can be used to reproduce the problem.