[PATCH] three annotations-related fixes/enhancements

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

[PATCH] three annotations-related fixes/enhancements

Jamison Hope
The attached patch fixes 2 bugs and provides 1 new feature:

1. When an annotation entry is read in via the readAnnotationEntry()
method of RuntimeAnnotationsAttr, it sets the entry's
annotationTypeIndex field, but not its annotationType field.  So then
later when the annotation is searched for later, we get a
NullPointerException in RuntimeAnnotationsAttr.getAnnotation() at this

if (ann.getAnnotationType().getReflectClass() == clas) {

because getAnnotationType() returns null.

The first fix is to initialize the annotationType field when the entry
is read in.

2. When an annotation value is read in via the readAnnotationValue()
method of RuntimeAnnotationsAttr, if the value type is an enum constant,
it is stored as a String[] holding the names of the enum class and
field.  Later on, getAnnotation() returns a Proxy object that will
call AnnotationEntry.Value.getValue().  This is supposed to return the
appropriate enum constant, but instead returns the String[], leading to
a ClassCastException (I think it was).

The second fix is to fix Value.getValue() so that if it's of type 'e'
(enum), then convert the String[] into the actual enum constant.

3. The third change is an enhancement to give ClassType a
getAnnotation() method analogous to the ones in Field and Method.

Jamison Hope
The PTR Group

gnu-bytecode-annotations.patch (3K) Download Attachment
Reply | Threaded
Open this post in threaded view

Re: [PATCH] three annotations-related fixes/enhancements

Per Bothner
On 08/13/2015 12:30 PM, Jamison Hope wrote:
> The attached patch fixes 2 bugs and provides 1 new feature:

Thanks!  I checked this in.
        --Per Bothner
[hidden email]   http://per.bothner.com/