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