RFC 8228988: Handle annotation values with incompatible runtime type
Rafael Winterhalter
rafael.wth at gmail.com
Thu Aug 1 18:42:32 UTC 2019
Hello, I tried to fix a bug in AnnotationParser that throws a
NullPointerException if an annotation enum property was refactored to an
enumeration type or vice versa but retained its old name.
There is currently no check if an annotation property is consistent with
the runtime type, only the existance of the type is validated which causes
this null pointer.
I struggled to write a test for Jtreg as this requires quite a lot of setup
but I hope that it is quite straight-forward to see from the changed code
segments that the validation is missing.
Nevertheless, I am not sure if this is the exception that would be expected
from such a scenario.
Here is the diff file inlined:
Index:
src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
---
src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java
(revision 55752:8ae33203d600a7c9f9b2be9b31a0eb8197270ab1)
+++
src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java
(revision 55752+:8ae33203d600+)
@@ -358,6 +358,9 @@
result = parseConst(tag, buf, constPool);
}
+ if (result == null)
+ result = new AnnotationTypeMismatchExceptionProxy(
+ memberType.getClass().getName());
if (!(result instanceof ExceptionProxy) &&
!memberType.isInstance(result))
result = new AnnotationTypeMismatchExceptionProxy(
@@ -470,7 +473,10 @@
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(
More information about the core-libs-dev
mailing list