commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joerg Schaible (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-696) Deprecate ClassUtils getShortClassName in favor of Class getSimpleName
Date Fri, 29 Apr 2011 17:20:03 GMT

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

Joerg Schaible commented on LANG-696:
-------------------------------------

There are actually more differences looking at classes defined within a method. The JDK version
suppresses the synthetic numbering:

{noformat}
Index: src/test/java/org/apache/commons/lang3/ClassUtilsTest.java
===================================================================
--- src/test/java/org/apache/commons/lang3/ClassUtilsTest.java  (revision 1097888)
+++ src/test/java/org/apache/commons/lang3/ClassUtilsTest.java  (working copy)
@@ -97,6 +97,11 @@
         assertEquals("String[][]", ClassUtils.getShortClassName(String[][].class));
         assertEquals("String[][][]", ClassUtils.getShortClassName(String[][][].class));
         assertEquals("String[][][][]", ClassUtils.getShortClassName(String[][][][].class));
+        
+        // on-the-fly types
+        class Named extends Object {};
+        assertEquals("ClassUtilsTest.1", ClassUtils.getShortClassName(new Object(){}.getClass()));
+        assertEquals("ClassUtilsTest.1Named", ClassUtils.getShortClassName(Named.class));
     }
 
 
@@ -141,6 +146,11 @@
         assertEquals("String[][]", ClassUtils.getSimpleName(String[][].class));
         assertEquals("String[][][]", ClassUtils.getSimpleName(String[][][].class));
         assertEquals("String[][][][]", ClassUtils.getSimpleName(String[][][][].class));
+        
+        // on-the-fly types
+        class Named extends Object {};
+        assertEquals("", ClassUtils.getSimpleName(new Object(){}.getClass()));
+        assertEquals("Named", ClassUtils.getSimpleName(Named.class));
     }
 
     public void test_getSimpleName_Object() {
{noformat}

> 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
>             Fix For: 3.x
>
>
> Added two null-safe ClassUtils.getSimpleName() APIs.
> ---------- Forwarded message ----------
> From: Gary Gregory <garydgregory@gmail.com>
> Date: Mon, Apr 11, 2011 at 10:18 AM
> Subject: [Lang] ClassUtils getShortClassName != Class getSimpleName
> To: Commons Developers List <dev@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 is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message