You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2019/10/08 15:47:00 UTC

[jira] [Work logged] (LANG-696) Deprecate ClassUtils getShortClassName in favor of Class getSimpleName

     [ https://issues.apache.org/jira/browse/LANG-696?focusedWorklogId=325138&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-325138 ]

ASF GitHub Bot logged work on LANG-696:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 08/Oct/19 15:46
            Start Date: 08/Oct/19 15:46
    Worklog Time Spent: 10m 
      Work Description: verhas commented on pull request #449: documentation related to the issue LANG-696
URL: https://github.com/apache/commons-lang/pull/449#discussion_r332590295
 
 

 ##########
 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:
   done as requested
 
----------------------------------------------------------------
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:
users@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 325138)
    Time Spent: 0.5h  (was: 20m)

> Deprecate ClassUtils getShortClassName in favor of Class getSimpleName
> ----------------------------------------------------------------------
>
>                 Key: LANG-696
>                 URL: https://issues.apache.org/jira/browse/LANG-696
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>    Affects Versions: 2.6
>            Reporter: Gary D. Gregory
>            Assignee: Gary D. Gregory
>            Priority: Major
>             Fix For: Discussion
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Added two null-safe ClassUtils.getSimpleName() APIs.
> ---------- Forwarded message ----------
> From: Gary Gregory <ga...@gmail.com>
> Date: Mon, Apr 11, 2011 at 10:18 AM
> Subject: [Lang] ClassUtils getShortClassName != Class getSimpleName
> To: Commons Developers List <de...@commons.apache.org>
> Hi All:
> Should we deprecate ClassUtils getShortClassName in favor of Class getSimpleName?
> The behavior of getShortClassName is undocumented for arrays in the Javadoc and is different from getSimpleName.
> When I replace the guts of getShortClassName to call getSimpleName, one test fails:
> junit.framework.ComparisonFailure: null expected:<[ToStringStyleTest.]Person[name=John Q. ...> but was:<[]Person[name=John Q. ...>
>     at junit.framework.Assert.assertEquals(Assert.java:81)
>     at junit.framework.Assert.assertEquals(Assert.java:87)
>     at org.apache.commons.lang3.builder.ShortPrefixToStringStyleTest.testPerson(ShortPrefixToStringStyleTest.java:86)
> For now, I've made a note in the Javdoc to consider using getSimpleName.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)