Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1691

ClassUtils.getShortCanonicalName doesn't use the canonicalName

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.12.0
    • 3.13.0
    • lang.*
    • None

    Description

      The getShortCanonicalName 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.

      Class<?> clazz = Map.Entry.class;
      System.out.println(ClassUtils.getShortCanonicalName(clazz)); 

      Actual: Map.Entry

      Expected: Entry

      Looking into the implementation, it calls getShortCanonicalName(cls.getName()). I believe it should have been getShortCanonicalName(cls.getCanonicalName())

      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));
      } 

       

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            thiyagu_7 Thiyagarajan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 1h 10m
                1h 10m