Skip to content

Commit cd87ec6

Browse files
committed
[LANG-1789] NullPointerException when generating NoSuchMethodException
in MethodUtils
1 parent 89bb309 commit cd87ec6

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The <action> type attribute can be add,update,fix,remove.
5353
<action type="fix" dev="ggregory" due-to="jack5505, Gary Gregory">`LocaleUtils.toLocale(String)` for a 2 letter country code now returns a value instead of throwing an `IllegalArgumentException`.</action>
5454
<action type="fix" dev="ggregory" due-to="mayuming, Gary Gregory">Fix typo in StringUtils.trunctate() IllegalArgumentException message and test assertion messages.</action>
5555
<action type="fix" dev="ggregory" due-to="mayuming, Gary Gregory">Fix test fixture in ReflectionDiffBuilderTest.testTransientFieldDifference() #1464.</action>
56+
<action issue="LANG-1789" type="fix" dev="ggregory" due-to="Hylke van der Schaaf, Gary Gregory">NullPointerException when generating NoSuchMethodException in MethodUtils.</action>
5657
<!-- ADD -->
5758
<action type="add" dev="ggregory" due-to="Gary Gregory">Add SystemProperties.getPath(String, Supplier&lt;Path&gt;).</action>
5859
<action type="add" dev="ggregory" due-to="Gary Gregory">Add JavaVersion.JAVA_25.</action>

src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ private static Method requireNonNull(final Method method, final Class<?> cls, fi
10231023
throws NoSuchMethodException {
10241024
if (method == null) {
10251025
throw new NoSuchMethodException(String.format("No method: %s.%s(%s)", cls.getName(), methodName,
1026-
Stream.of(parameterTypes).map(Class::getName).collect(LangCollectors.joining(", "))));
1026+
Stream.of(parameterTypes).map(c -> c != null ? c.getName() : null).collect(LangCollectors.joining(", "))));
10271027
}
10281028
return method;
10291029
}

src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,9 @@ void testInvokeMethod() throws Exception {
11101110
void testInvokeMethod_VarArgsWithNullValues() throws Exception {
11111111
assertEquals("String...", MethodUtils.invokeMethod(testBean, "varOverload", "a", null, "c"));
11121112
assertEquals("String...", MethodUtils.invokeMethod(testBean, "varOverload", "a", "b", null));
1113+
assertEquals("String...", MethodUtils.invokeMethod(testBean, "varOverload", new String[] { "a" }, new Class<?>[] { String.class }));
1114+
assertThrows(NoSuchMethodException.class,
1115+
() -> assertEquals("String...", MethodUtils.invokeMethod(testBean, "doesn't exist", new String[] { "a" }, new Class<?>[] { null })));
11131116
}
11141117

11151118
@Test

0 commit comments

Comments
 (0)