Stzx commented on a change in pull request #449: documentation related to the issue LANG-696 URL: https://github.com/apache/commons-lang/pull/449#discussion_r318364989
########## File path: src/test/java/org/apache/commons/lang3/ClassUtilsTest.java ########## @@ -513,20 +516,34 @@ public void test_getShortCanonicalName_Object() { @Test public void test_getShortCanonicalName_String() { + assertEquals("", ClassUtils.getShortCanonicalName((String)null)); + assertEquals("Map.Entry", ClassUtils.getShortCanonicalName(java.util.Map.Entry.class.getName())); + assertEquals("Entry", ClassUtils.getShortCanonicalName(java.util.Map.Entry.class.getCanonicalName())); assertEquals("ClassUtils", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils")); assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName("[Lorg.apache.commons.lang3.ClassUtils;")); assertEquals("ClassUtils[][]", ClassUtils.getShortCanonicalName("[[Lorg.apache.commons.lang3.ClassUtils;")); assertEquals("ClassUtils[]", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils[]")); assertEquals("ClassUtils[][]", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtils[][]")); assertEquals("int[]", ClassUtils.getShortCanonicalName("[I")); + assertEquals("int[]", ClassUtils.getShortCanonicalName(int[].class.getCanonicalName())); + assertEquals("int[]", ClassUtils.getShortCanonicalName(int[].class.getName())); assertEquals("int[][]", ClassUtils.getShortCanonicalName("[[I")); assertEquals("int[]", ClassUtils.getShortCanonicalName("int[]")); assertEquals("int[][]", ClassUtils.getShortCanonicalName("int[][]")); - // Inner types + // this is to demonstrate that the documentation and the naming of the methods + // uses the class name and canonical name totally mixed up, which cannot be + // fixed without backward compatibility break + assertEquals("int[]", int[].class.getCanonicalName()); + assertEquals("[I", int[].class.getName()); + + // Inner types... the problem is that these are not canonical names, classes with this name do not even have canonical name assertEquals("ClassUtilsTest.6", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$6")); assertEquals("ClassUtilsTest.5Named", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$5Named")); assertEquals("ClassUtilsTest.Inner", ClassUtils.getShortCanonicalName("org.apache.commons.lang3.ClassUtilsTest$Inner")); + // demonstrating what a canonical name is... it is a bigger issue to clean this up + assertEquals("org.apache.commons.lang3.ClassUtilsTest$10", new org.apache.commons.lang3.ClassUtilsTest(){}.getClass().getName()); Review comment: The addition of the inner class will cause the compilation identifier InnerClassName to move backwards. You need to modify ``` assertEquals("ClassUtilsTest.10", ClassUtils.getShortClassName(new Object() { // empty }.getClass())); ``` to ``` assertEquals("ClassUtilsTest.12", ClassUtils.getShortClassName(new Object() { // empty }.getClass())); ``` and ``` assertEquals("ClassUtilsTest.11", ClassUtils.getShortClassName(new Object() { // empty }, "<null>")); ``` to ``` assertEquals("ClassUtilsTest.13", ClassUtils.getShortClassName(new Object() { // empty }, "<null>")); ``` And adding warning notes like [487 lines](https://github.com/apache/commons-lang/blob/479d2c85083fd127b2d4fcfbf184267c76275350/src/test/java/org/apache/commons/lang3/ClassUtilsTest.java#L487). ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services