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 b62244517 Fix ClassNotFoundException message variable (#1577)
b62244517 is described below
commit b6224451728562b0a4b33b63e8589753b1e2a57c
Author: 烂泥扶上墙 <[email protected]>
AuthorDate: Fri Jan 23 03:36:08 2026 +0800
Fix ClassNotFoundException message variable (#1577)
* Fix ClassNotFoundException message variable
* Improve exception assertion in ClassUtilsTest
Update exception handling in assertGetClassThrowsException method to
capture and verify exception messages.
* Fix indentation.
---------
Co-authored-by: Gary Gregory <[email protected]>
---
src/main/java/org/apache/commons/lang3/ClassUtils.java | 2 +-
src/test/java/org/apache/commons/lang3/ClassUtilsTest.java | 6 +++++-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/lang3/ClassUtils.java
b/src/main/java/org/apache/commons/lang3/ClassUtils.java
index b4bfd4d22..5c2cf099d 100644
--- a/src/main/java/org/apache/commons/lang3/ClassUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ClassUtils.java
@@ -601,7 +601,7 @@ public static Class<?> getClass(final ClassLoader
classLoader, final String clas
}
}
} while (lastDotIndex != -1);
- throw new ClassNotFoundException(next);
+ throw new ClassNotFoundException(className);
}
/**
diff --git a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
index 9029bb1e3..abe8004e4 100644
--- a/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
@@ -110,8 +110,11 @@ private void assertGetClassThrowsClassNotFound(final
String className) {
}
private void assertGetClassThrowsException(final String className, final
Class<? extends Exception> exceptionType) {
- assertThrows(exceptionType, () -> ClassUtils.getClass(className),
+ final Exception exception = assertThrows(exceptionType, () ->
ClassUtils.getClass(className),
"ClassUtils.getClass() should fail with an exception of type " +
exceptionType.getName() + " when given class name \"" + className + "\".");
+ if (className != null) {
+ assertEquals(className, exception.getMessage());
+ }
}
private void assertGetClassThrowsNullPointerException(final String
className) {
@@ -1251,6 +1254,7 @@ void testGetClassClassNotFound() throws Exception {
assertGetClassThrowsClassNotFound("bool");
assertGetClassThrowsClassNotFound("bool[]");
assertGetClassThrowsClassNotFound("integer[]");
+
assertGetClassThrowsClassNotFound("org.apache.commons.lang3.ClassUtilsTest.AClassThatCannotBeFound");
}
@Test