Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/org/apache/commons/lang3/ClassUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ private static String getCanonicalName(final String name) {
className = className.substring(dim);
if (className.startsWith("L")) {
className = className.substring(1, className.endsWith(";") ? className.length() - 1 : className.length());
} else if (!className.isEmpty()) {
className = reverseAbbreviationMap.get(className.substring(0, 1));
} else if (className.length() == 1 && reverseAbbreviationMap.containsKey(className)) {
className = reverseAbbreviationMap.get(className);
}
final StringBuilder canonicalClassNameBuffer = new StringBuilder(className.length() + dim * 2);
canonicalClassNameBuffer.append(className);
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ public void test_getAllSuperclasses_Class() {
assertNull(ClassUtils.getAllSuperclasses(null));
}

@Test
public void test_getShortCanonicalName_MalformedInput() {
assertEquals("String[]", ClassUtils.getShortCanonicalName("[String"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see how "[String" is a legal name, but "[Ljava.lang.String;" is legal. Do you read the JLS to allow this? For an unpackaged class Foo, an array would be "[LFoo;".

}
@Test
public void test_getShortCanonicalName_MissingSemicolon() {
assertEquals("String[]", ClassUtils.getShortCanonicalName("[LString"));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see how "[LString" is a legal name, but "[Ljava.lang.String;" is legal. Do you read the JLS to allow this? For an unpackaged class Foo, an array would be "[LFoo;".

}

@Test
public void test_getCanonicalName_Class() {
assertEquals("org.apache.commons.lang3.ClassUtils", ClassUtils.getCanonicalName(ClassUtils.class));
Expand Down