diff options
author | Brian Carlstrom <bdc@google.com> | 2014-02-20 19:19:00 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-02-20 19:19:00 +0000 |
commit | 84c957a479f28ebf8b15c757add4be75a3960ceb (patch) | |
tree | 68542bc3e93f4bfd199cf8886896a2b2095fd1fe /luni | |
parent | 6d9b21a13ad3e8c2fb82427b1ddb967668425467 (diff) | |
parent | cc346026b56ca68149b9f1cbbb42136e09ef0be3 (diff) | |
download | libcore-84c957a479f28ebf8b15c757add4be75a3960ceb.zip libcore-84c957a479f28ebf8b15c757add4be75a3960ceb.tar.gz libcore-84c957a479f28ebf8b15c757add4be75a3960ceb.tar.bz2 |
Merge "When decoding enum annotation value, treat it as a field name, not enum value"
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; |