Avoid throwing checked exceptions from AnnotationUtils.hashCode()
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1077895 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ed69b85620
commit
4046e160ff
|
@ -135,9 +135,9 @@ public class AnnotationUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException ex) {
|
||||||
return false;
|
return false;
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -155,17 +155,22 @@ public class AnnotationUtils {
|
||||||
* @throws IllegalAccessException if thrown during annotation access
|
* @throws IllegalAccessException if thrown during annotation access
|
||||||
* @throws InvocationTargetException if thrown during annotation access
|
* @throws InvocationTargetException if thrown during annotation access
|
||||||
*/
|
*/
|
||||||
public static int hashCode(Annotation a)
|
public static int hashCode(Annotation a) {
|
||||||
throws IllegalAccessException, InvocationTargetException {
|
|
||||||
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()) {
|
||||||
|
try {
|
||||||
Object value = m.invoke(a);
|
Object value = m.invoke(a);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
String.format("Annotation method %s returned null", m));
|
String.format("Annotation method %s returned null", m));
|
||||||
}
|
}
|
||||||
result += hashMember(m.getName(), value);
|
result += hashMember(m.getName(), value);
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
throw ex;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -185,10 +190,10 @@ public class AnnotationUtils {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
builder.append(m.getName(), m.invoke(a));
|
builder.append(m.getName(), m.invoke(a));
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException ex) {
|
||||||
throw e;
|
throw ex;
|
||||||
} catch (Exception e) {
|
} catch (Exception ex) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
Loading…
Reference in New Issue