Skip to content

Commit 57f493a

Browse files
committed
IO-487 - include class name in InvalidClassException
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1715221 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7f292bf commit 57f493a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/main/java/org/apache/commons/io/serialization/ValidatingObjectInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private void validateClassName(String name) throws InvalidClassException {
9393
* @throws InvalidClassException
9494
*/
9595
protected void invalidClassNameFound(String className) throws InvalidClassException{
96-
throw new InvalidClassException("Class name not accepted");
96+
throw new InvalidClassException("Class name not accepted: " + className);
9797
}
9898

9999
@Override

src/test/java/org/apache/commons/io/serialization/ValidatingObjectInputStreamTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
package org.apache.commons.io.serialization;
2020

21+
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.fail;
2123
import static org.junit.Assert.assertEquals;
2224

2325
import java.io.ByteArrayInputStream;
@@ -85,6 +87,18 @@ public void noAccept() throws Exception {
8587
willClose(new ValidatingObjectInputStream(testStream)));
8688
}
8789

90+
@Test
91+
public void exceptionIncludesClassName() throws Exception {
92+
try {
93+
assertSerialization(
94+
willClose(new ValidatingObjectInputStream(testStream)));
95+
fail("Expected an InvalidClassException");
96+
} catch(InvalidClassException ice) {
97+
final String name = OurTestClass.class.getName();
98+
assertTrue("Expecting message to contain " + name, ice.getMessage().contains(name));
99+
}
100+
}
101+
88102
@Test
89103
public void acceptCustomMatcher() throws Exception {
90104
assertSerialization(

0 commit comments

Comments
 (0)