[Spotbugs 4.7.0] More precise exception handling, don't throw
RuntimeException, use our own UncheckedException.
This commit is contained in:
parent
af157c49d5
commit
f813045283
|
@ -17,12 +17,12 @@
|
||||||
package org.apache.commons.lang3;
|
package org.apache.commons.lang3;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
import org.apache.commons.lang3.exception.UncheckedException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Helper methods for working with {@link Annotation} instances.</p>
|
* <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 false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -161,14 +161,11 @@ public class AnnotationUtils {
|
||||||
try {
|
try {
|
||||||
final Object value = m.invoke(a);
|
final 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 (final RuntimeException ex) {
|
} catch (final ReflectiveOperationException ex) {
|
||||||
throw ex;
|
throw new UncheckedException(ex);
|
||||||
} catch (final Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -186,14 +183,12 @@ public class AnnotationUtils {
|
||||||
final ToStringBuilder builder = new ToStringBuilder(a, TO_STRING_STYLE);
|
final ToStringBuilder builder = new ToStringBuilder(a, TO_STRING_STYLE);
|
||||||
for (final Method m : a.annotationType().getDeclaredMethods()) {
|
for (final Method m : a.annotationType().getDeclaredMethods()) {
|
||||||
if (m.getParameterTypes().length > 0) {
|
if (m.getParameterTypes().length > 0) {
|
||||||
continue; //wtf?
|
continue; // wtf?
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
builder.append(m.getName(), m.invoke(a));
|
builder.append(m.getName(), m.invoke(a));
|
||||||
} catch (final RuntimeException ex) {
|
} catch (final ReflectiveOperationException ex) {
|
||||||
throw ex;
|
throw new UncheckedException(ex);
|
||||||
} catch (final Exception ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
|
Loading…
Reference in New Issue