Skip to content

Commit b622445

Browse files
eirvgarydgregory
andauthored
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 <garydgregory@users.noreply.github.com>
1 parent c4ea2b0 commit b622445

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

src/main/java/org/apache/commons/lang3/ClassUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ public static Class<?> getClass(final ClassLoader classLoader, final String clas
601601
}
602602
}
603603
} while (lastDotIndex != -1);
604-
throw new ClassNotFoundException(next);
604+
throw new ClassNotFoundException(className);
605605
}
606606

607607
/**

src/test/java/org/apache/commons/lang3/ClassUtilsTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,11 @@ private void assertGetClassThrowsClassNotFound(final String className) {
110110
}
111111

112112
private void assertGetClassThrowsException(final String className, final Class<? extends Exception> exceptionType) {
113-
assertThrows(exceptionType, () -> ClassUtils.getClass(className),
113+
final Exception exception = assertThrows(exceptionType, () -> ClassUtils.getClass(className),
114114
"ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\".");
115+
if (className != null) {
116+
assertEquals(className, exception.getMessage());
117+
}
115118
}
116119

117120
private void assertGetClassThrowsNullPointerException(final String className) {
@@ -1251,6 +1254,7 @@ void testGetClassClassNotFound() throws Exception {
12511254
assertGetClassThrowsClassNotFound("bool");
12521255
assertGetClassThrowsClassNotFound("bool[]");
12531256
assertGetClassThrowsClassNotFound("integer[]");
1257+
assertGetClassThrowsClassNotFound("org.apache.commons.lang3.ClassUtilsTest.AClassThatCannotBeFound");
12541258
}
12551259

12561260
@Test

0 commit comments

Comments
 (0)