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 cd87ec61b [LANG-1789] NullPointerException when generating
NoSuchMethodException in MethodUtils
cd87ec61b is described below
commit cd87ec61b8d0b3274d6b348397802b46cd1c0247
Author: Gary D. Gregory <[email protected]>
AuthorDate: Tue Oct 14 07:49:41 2025 -0400
[LANG-1789] NullPointerException when generating NoSuchMethodException
in MethodUtils
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java | 2 +-
src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java | 3 +++
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f0a483be0..95a239b84 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -53,6 +53,7 @@ The <action> type attribute can be add,update,fix,remove.
<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>
<action type="fix" dev="ggregory" due-to="mayuming, Gary
Gregory">Fix typo in StringUtils.trunctate() IllegalArgumentException message
and test assertion messages.</action>
<action type="fix" dev="ggregory" due-to="mayuming, Gary
Gregory">Fix test fixture in
ReflectionDiffBuilderTest.testTransientFieldDifference() #1464.</action>
+ <action issue="LANG-1789" type="fix" dev="ggregory" due-to="Hylke van der
Schaaf, Gary Gregory">NullPointerException when generating
NoSuchMethodException in MethodUtils.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary
Gregory">Add SystemProperties.getPath(String, Supplier<Path>).</action>
<action type="add" dev="ggregory" due-to="Gary
Gregory">Add JavaVersion.JAVA_25.</action>
diff --git a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
index 799178139..5bebd9b3e 100644
--- a/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
+++ b/src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java
@@ -1023,7 +1023,7 @@ private static Method requireNonNull(final Method method,
final Class<?> cls, fi
throws NoSuchMethodException {
if (method == null) {
throw new NoSuchMethodException(String.format("No method:
%s.%s(%s)", cls.getName(), methodName,
-
Stream.of(parameterTypes).map(Class::getName).collect(LangCollectors.joining(",
"))));
+ Stream.of(parameterTypes).map(c -> c != null ? c.getName()
: null).collect(LangCollectors.joining(", "))));
}
return method;
}
diff --git
a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
index f90fb2918..3ab33c5fd 100644
--- a/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
@@ -1110,6 +1110,9 @@ void testInvokeMethod() throws Exception {
void testInvokeMethod_VarArgsWithNullValues() throws Exception {
assertEquals("String...", MethodUtils.invokeMethod(testBean,
"varOverload", "a", null, "c"));
assertEquals("String...", MethodUtils.invokeMethod(testBean,
"varOverload", "a", "b", null));
+ assertEquals("String...", MethodUtils.invokeMethod(testBean,
"varOverload", new String[] { "a" }, new Class<?>[] { String.class }));
+ assertThrows(NoSuchMethodException.class,
+ () -> assertEquals("String...",
MethodUtils.invokeMethod(testBean, "doesn't exist", new String[] { "a" }, new
Class<?>[] { null })));
}
@Test