mirror of
https://github.com/corda/corda.git
synced 2025-01-03 19:54:13 +00:00
Merge pull request #234 from dicej/field_getAnnotations
fix NPE in Field.getAnnotations
This commit is contained in:
commit
b01515ac84
@ -348,8 +348,13 @@ public class Field<T> extends AccessibleObject {
|
||||
return (Annotation) a[0];
|
||||
}
|
||||
|
||||
private boolean hasAnnotations() {
|
||||
return vmField.addendum != null
|
||||
&& vmField.addendum.annotationTable != null;
|
||||
}
|
||||
|
||||
public <T extends Annotation> T getAnnotation(Class<T> class_) {
|
||||
if (vmField.addendum != null && vmField.addendum.annotationTable != null) {
|
||||
if (hasAnnotations()) {
|
||||
Object[] table = (Object[]) vmField.addendum.annotationTable;
|
||||
for (int i = 0; i < table.length; ++i) {
|
||||
Object[] a = (Object[]) table[i];
|
||||
@ -362,7 +367,7 @@ public class Field<T> extends AccessibleObject {
|
||||
}
|
||||
|
||||
public Annotation[] getAnnotations() {
|
||||
if (vmField.addendum.annotationTable != null) {
|
||||
if (hasAnnotations()) {
|
||||
Object[] table = (Object[]) vmField.addendum.annotationTable;
|
||||
Annotation[] array = new Annotation[table.length];
|
||||
for (int i = 0; i < table.length; ++i) {
|
||||
|
@ -252,6 +252,9 @@ public class Reflection {
|
||||
|
||||
expect(avian.testing.annotations.Test.class.getPackage().getName().equals
|
||||
("avian.testing.annotations"));
|
||||
|
||||
expect(Baz.class.getField("foo").getAnnotation(Ann.class) == null);
|
||||
expect(Baz.class.getField("foo").getAnnotations().length == 0);
|
||||
}
|
||||
|
||||
protected static class Baz {
|
||||
@ -280,3 +283,5 @@ interface A {
|
||||
}
|
||||
|
||||
interface B extends A { }
|
||||
|
||||
@interface Ann { }
|
||||
|
Loading…
Reference in New Issue
Block a user