address the invalidity of null annotation members

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1073995 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Jason Benson 2011-02-24 00:05:02 +00:00
parent 9e4b248d48
commit ad549f8f34

View File

@ -148,7 +148,12 @@ public static int hashCode(Annotation a) throws IllegalArgumentException,
int result = 0; int result = 0;
Class<? extends Annotation> type = a.annotationType(); Class<? extends Annotation> type = a.annotationType();
for (Method m : type.getDeclaredMethods()) { for (Method m : type.getDeclaredMethods()) {
result += hashMember(m.getName(), m.invoke(a)); Object value = m.invoke(a);
if (value == null) {
throw new IllegalStateException(String.format("Annotation method %s returned null",
m));
}
result += hashMember(m.getName(), value);
} }
return result; return result;
} }
@ -198,9 +203,6 @@ public static boolean isValidAnnotationMemberType(Class<?> type) {
private static int hashMember(String name, Object value) throws IllegalArgumentException, private static int hashMember(String name, Object value) throws IllegalArgumentException,
IllegalAccessException, InvocationTargetException { IllegalAccessException, InvocationTargetException {
int part1 = name.hashCode() * 127; int part1 = name.hashCode() * 127;
if (value == null) {
return part1;
}
if (value.getClass().isArray()) { if (value.getClass().isArray()) {
return part1 ^ arrayMemberHash(value.getClass().getComponentType(), value); return part1 ^ arrayMemberHash(value.getClass().getComponentType(), value);
} }