[
https://issues.apache.org/jira/browse/LANG-696?focusedWorklogId=302497&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-302497
]
ASF GitHub Bot logged work on LANG-696:
---------------------------------------
Author: ASF GitHub Bot
Created on: 28/Aug/19 02:03
Start Date: 28/Aug/19 02:03
Worklog Time Spent: 10m
Work Description: Stzx commented on 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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 302497)
Time Spent: 20m (was: 10m)
> 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 Gregory
> Assignee: Gary Gregory
> Priority: Major
> Fix For: Discussion
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> Added two null-safe ClassUtils.getSimpleName() APIs.
> ---------- Forwarded message ----------
> From: Gary Gregory <[email protected]>
> Date: Mon, Apr 11, 2011 at 10:18 AM
> Subject: [Lang] ClassUtils getShortClassName != Class getSimpleName
> To: Commons Developers List <[email protected]>
> 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.2#803003)