diff options
author | Brian Carlstrom <bdc@google.com> | 2014-02-20 09:03:45 -0800 |
---|---|---|
committer | Brian Carlstrom <bdc@google.com> | 2014-02-20 09:19:07 -0800 |
commit | cc346026b56ca68149b9f1cbbb42136e09ef0be3 (patch) | |
tree | 68542bc3e93f4bfd199cf8886896a2b2095fd1fe /luni | |
parent | 6d9b21a13ad3e8c2fb82427b1ddb967668425467 (diff) | |
download | libcore-cc346026b56ca68149b9f1cbbb42136e09ef0be3.zip libcore-cc346026b56ca68149b9f1cbbb42136e09ef0be3.tar.gz libcore-cc346026b56ca68149b9f1cbbb42136e09ef0be3.tar.bz2 |
When decoding enum annotation value, treat it as a field name, not enum value
Bug: 13078746
Change-Id: I9971841aee3a061523f7ef4744de8042269c1763
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/java/libcore/reflect/AnnotationAccess.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/luni/src/main/java/libcore/reflect/AnnotationAccess.java b/luni/src/main/java/libcore/reflect/AnnotationAccess.java index c2b54ce..6ff82c4 100644 --- a/luni/src/main/java/libcore/reflect/AnnotationAccess.java +++ b/luni/src/main/java/libcore/reflect/AnnotationAccess.java @@ -708,10 +708,20 @@ public final class AnnotationAccess { } else if (type.isEnum()) { int fieldIndex = reader.readEnum(); FieldId fieldId = dex.fieldIds().get(fieldIndex); - String enumName = dex.strings().get(fieldId.getNameIndex()); - @SuppressWarnings({"unchecked", "rawtypes"}) // Class.isEnum is the runtime check - Class<? extends Enum> enumType = (Class<? extends Enum>) type; - return Enum.valueOf(enumType, enumName); + String fieldName = dex.strings().get(fieldId.getNameIndex()); + Field field; + try { + field = type.getDeclaredField(fieldName); + return field.get(null); + } catch (NoSuchFieldException e) { + NoSuchFieldError error = new NoSuchFieldError(); + error.initCause(e); + throw error; + } catch (IllegalAccessException e) { + IllegalAccessError error = new IllegalAccessError(); + error.initCause(e); + throw error; + } } else if (type.isAnnotation()) { @SuppressWarnings("unchecked") // Class.isAnnotation is the runtime check Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) type; |