You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/05/15 20:21:54 UTC
[commons-lang] branch master updated: [Spotbugs 4.7.0] More precise exception handling, don't throw RuntimeException, use our own UncheckedException.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-lang.git
The following commit(s) were added to refs/heads/master by this push:
new f81304528 [Spotbugs 4.7.0] More precise exception handling, don't throw RuntimeException, use our own UncheckedException.
f81304528 is described below
commit f813045283ffde51c8b01c76cb8300a6c55d8a1e
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 15 16:21:49 2022 -0400
[Spotbugs 4.7.0] More precise exception handling, don't throw
RuntimeException, use our own UncheckedException.
---
.../org/apache/commons/lang3/AnnotationUtils.java | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/AnnotationUtils.java b/src/main/java/org/apache/commons/lang3/AnnotationUtils.java
index d2bb95615..6beb7ca8e 100644
--- a/src/main/java/org/apache/commons/lang3/AnnotationUtils.java
+++ b/src/main/java/org/apache/commons/lang3/AnnotationUtils.java
@@ -17,12 +17,12 @@
package org.apache.commons.lang3;
import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
+import org.apache.commons.lang3.exception.UncheckedException;
/**
* <p>Helper methods for working with {@link Annotation} instances.</p>
@@ -136,7 +136,7 @@ public class AnnotationUtils {
}
}
}
- } catch (final IllegalAccessException | InvocationTargetException ex) {
+ } catch (final ReflectiveOperationException ex) {
return false;
}
return true;
@@ -161,14 +161,11 @@ public class AnnotationUtils {
try {
final Object value = m.invoke(a);
if (value == null) {
- throw new IllegalStateException(
- String.format("Annotation method %s returned null", m));
+ throw new IllegalStateException(String.format("Annotation method %s returned null", m));
}
result += hashMember(m.getName(), value);
- } catch (final RuntimeException ex) {
- throw ex;
- } catch (final Exception ex) {
- throw new RuntimeException(ex);
+ } catch (final ReflectiveOperationException ex) {
+ throw new UncheckedException(ex);
}
}
return result;
@@ -186,14 +183,12 @@ public class AnnotationUtils {
final ToStringBuilder builder = new ToStringBuilder(a, TO_STRING_STYLE);
for (final Method m : a.annotationType().getDeclaredMethods()) {
if (m.getParameterTypes().length > 0) {
- continue; //wtf?
+ continue; // wtf?
}
try {
builder.append(m.getName(), m.invoke(a));
- } catch (final RuntimeException ex) {
- throw ex;
- } catch (final Exception ex) {
- throw new RuntimeException(ex);
+ } catch (final ReflectiveOperationException ex) {
+ throw new UncheckedException(ex);
}
}
return builder.build();