Returning null from visitAnnotation causes a NPE
I created a simple class visitor to detect the package of a class. Therefore
visitAnnotation returns null, because I am not interested in this
information. Now ClassReader never checks the return value of visitAnnotation
and uses it, whenever annotations appear. This creates a NPE. I found the bug
with ASM 2.2.1, but it is still existing in 3.0 beta 2. A simple chekc of the
return value in the accept method of ClassReader should solve this problem.
current code:
// visits the class annotations
for (i = 1; i >= 0; --i) {
v = i == 0 ? ianns : anns;
if (v != 0) {
j = readUnsignedShort(v);
v += 2;
for (; j > 0; --j) {
desc = readUTF8(v, c);
v += 2;
v = readAnnotationValues(v,
c,
classVisitor.visitAnnotation(desc, i != 0));
}
}
}
possible fix
// visits the class annotations
for (i = 1; i >= 0; --i) {
v = i == 0 ? ianns : anns;
if (v != 0) {
j = readUnsignedShort(v);
v += 2;
for (; j > 0; --j) {
desc = readUTF8(v, c);
v += 2;
AnnotationVisitor av = classVisitor.visitAnnotation(desc,
i != 0);
if (av != null)
v = readAnnotationValues(v, c, av);
}
}
}