8228988: AnnotationParser throws NullPointerException on incompatible member type

Reviewed-by: darcy
This commit is contained in:
Rafael Winterhalter 2021-04-20 21:33:19 +00:00 committed by Joe Darcy
parent d61345984d
commit f47faf283b
3 changed files with 182 additions and 4 deletions

View file

@ -358,10 +358,14 @@ public class AnnotationParser {
result = parseConst(tag, buf, constPool);
}
if (!(result instanceof ExceptionProxy) &&
!memberType.isInstance(result))
if (result == null) {
result = new AnnotationTypeMismatchExceptionProxy(
memberType.getClass().getName());
} else if (!(result instanceof ExceptionProxy) &&
!memberType.isInstance(result)) {
result = new AnnotationTypeMismatchExceptionProxy(
result.getClass() + "[" + result + "]");
}
return result;
}
@ -469,8 +473,10 @@ public class AnnotationParser {
String typeName = constPool.getUTF8At(typeNameIndex);
int constNameIndex = buf.getShort() & 0xFFFF;
String constName = constPool.getUTF8At(constNameIndex);
if (!typeName.endsWith(";")) {
if (!enumType.isEnum()) {
return new AnnotationTypeMismatchExceptionProxy(
typeName + "." + constName);
} else if (!typeName.endsWith(";")) {
// support now-obsolete early jsr175-format class files.
if (!enumType.getName().equals(typeName))
return new AnnotationTypeMismatchExceptionProxy(