Skip to content

Commit 8bb5e61

Browse files
committed
Use Objects.requireNonNull()
1 parent d0a83f4 commit 8bb5e61

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.lang.ref.WeakReference;
2525
import java.lang.reflect.Method;
2626
import java.lang.reflect.Modifier;
27+
import java.util.Objects;
2728

2829
/**
2930
* A MappedPropertyDescriptor describes one mapped property.
@@ -50,13 +51,15 @@ public class MappedPropertyDescriptor extends PropertyDescriptor {
5051
* See http://issues.apache.org/jira/browse/BEANUTILS-291
5152
*/
5253
private static class MappedMethodReference {
54+
5355
private String className;
5456
private String methodName;
5557
private Reference<Method> methodRef;
5658
private Reference<Class<?>> classRef;
5759
private Reference<Class<?>> writeParamTypeRef0;
5860
private Reference<Class<?>> writeParamTypeRef1;
5961
private String[] writeParamClassNames;
62+
6063
MappedMethodReference(final Method m) {
6164
if (m != null) {
6265
className = m.getDeclaringClass().getName();
@@ -91,10 +94,7 @@ private Method get() {
9194
classRef = new WeakReference<>(clazz);
9295
}
9396
}
94-
if (clazz == null) {
95-
throw new RuntimeException("Method " + methodName + " for " +
96-
className + " could not be reconstructed - class reference has gone");
97-
}
97+
Objects.requireNonNull(clazz, () -> "Method " + methodName + " for " + className + " could not be reconstructed - class reference has gone");
9898
Class<?>[] paramTypes = null;
9999
if (writeParamClassNames != null) {
100100
paramTypes = new Class[2];
@@ -122,8 +122,7 @@ private Method get() {
122122
// Un-comment following line for testing
123123
// System.out.println("Recreated Method " + methodName + " for " + className);
124124
} catch (final NoSuchMethodException e) {
125-
throw new RuntimeException("Method " + methodName + " for " +
126-
className + " could not be reconstructed - method not found");
125+
throw new RuntimeException("Method " + methodName + " for " + className + " could not be reconstructed - method not found", e);
127126
}
128127
methodRef = new SoftReference<>(m);
129128
}

0 commit comments

Comments
 (0)