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 2022/09/15 14:36:00 UTC

[jira] [Work logged] (LANG-1691) ClassUtils.getShortCanonicalName doesn't use the canonicalName

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

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

                Author: ASF GitHub Bot
            Created on: 15/Sep/22 14:35
            Start Date: 15/Sep/22 14:35
    Worklog Time Spent: 10m 
      Work Description: thiyagu-7 opened a new pull request, #949:
URL: https://github.com/apache/commons-lang/pull/949

   JIRA issue - https://issues.apache.org/jira/browse/LANG-1691
   
   The `getShortCanonicalName` is using class name rather than the canonical name. Fixing it by using the canonicalName.
   Also updated the unit tests because of this change. For some of the tests, the canonical name will be null and hence changed the expected value to be an empty string. For inner class, the output will not have the outer class name.




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

            Worklog Id:     (was: 809111)
    Remaining Estimate: 0h
            Time Spent: 10m

> ClassUtils.getShortCanonicalName doesn't use the canonicalName
> --------------------------------------------------------------
>
>                 Key: LANG-1691
>                 URL: https://issues.apache.org/jira/browse/LANG-1691
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>    Affects Versions: 3.12.0
>            Reporter: Thiyagarajan
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The [getShortCanonicalName|https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/ClassUtils.html#getShortCanonicalName-java.lang.Class-] should return the canonical name minus the package name from a Class.
> Also, the javadoc of an overloaded _getShortCanonicalName_ states,
> _If the class is an inner class then the result value will not contain the outer classes. This way the behavior of this method is different from getShortClassName(String). The argument in that case is class name and not canonical name and the return value retains the outer classes._
> But for inner class, its behaviour is similar to _getShortClassName._
> {code:java}
> Class<?> clazz = Map.Entry.class;
> System.out.println(ClassUtils.getShortCanonicalName(clazz)); {code}
> *Actual:* Map.Entry
> *Expected:* Entry
> Looking into the implementation, it calls *getShortCanonicalName(cls.getName()).* I believe it should have been *getShortCanonicalName(cls.getCanonicalName())*
> {code:java}
> public static String getShortCanonicalName(final Class<?> cls) {
>     if (cls == null) {
>         return StringUtils.EMPTY;
>     }
>     return getShortCanonicalName(cls.getName()); //<---
> }
> public static String getShortCanonicalName(final String canonicalName) {
>     return getShortClassName(getCanonicalName(canonicalName));
> } {code}
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)