Merge pull request #99 from dscho/fix-get-annotation

Fix NPE in Field#getAnnotation
This commit is contained in:
Joshua Warner 2013-11-06 09:03:45 -08:00
commit dd460ab55e
2 changed files with 9 additions and 1 deletions

View File

@ -304,7 +304,7 @@ public class Field<T> extends AccessibleObject {
}
public <T extends Annotation> T getAnnotation(Class<T> class_) {
if (vmField.addendum.annotationTable != null) {
if (vmField.addendum != null && vmField.addendum.annotationTable != null) {
Object[] table = (Object[]) vmField.addendum.annotationTable;
for (int i = 0; i < table.length; ++i) {
Object[] a = (Object[]) table[i];

View File

@ -47,8 +47,16 @@ public class Reflection {
expect(Hello.class == inner[0]);
}
private int egads;
private static void annotations() throws Exception {
Field egads = Reflection.class.getDeclaredField("egads");
expect(egads.getAnnotation(Deprecated.class) == null);
}
public static void main(String[] args) throws Exception {
innerClasses();
annotations();
Class system = Class.forName("java.lang.System");
Field out = system.getDeclaredField("out");