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

ClassUtils getAbbreviatedName uses len one character shorter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: In Progress
    • Minor
    • Resolution: Unresolved
    • 3.9
    • None
    • None
    • None

    Description

      The ClassUtils method getAbbreviatedName calculates the required lenght one character short. That way

      final String ANY_CLASS_FULL_NAME = "....";
      
      assertEquals("ANY_CLASS_FULL_NAME ", ClassUtils.getAbbreviatedName(ANY_CLASS_FULL_NAME , ANY_CLASS_FULL_NAME .length()));
      

      will abbreviate the class name, although we are asking exactly the same number of characters as they are there. The solution is that

      if (availableSpace > 0) {
      

      has to be modified to

      if (availableSpace >= 0) {
      

      since the value zero means that we exactly used up the available character width.

      This is just a quick fix for this issue, but generally, the algorithm is faulty. It runs many times out of the desired length. It actually uses the len parameter, not as the desired final length but rather a length for which what is out of the range on the left that has to be abbreviated. For that, the code could be much simpler. (See LANG-1480.)

      Attachments

        Issue Links

          Activity

            People

              kinow Bruno P. Kinoshita
              peter@verhas.com Peter Verhas
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Time Tracking

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