[jira] [Work logged] (LANG-1478) ClassUtils getAbbreviatedName uses len one character shorter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Work logged] (LANG-1478) ClassUtils getAbbreviatedName uses len one character shorter

ASF GitHub Bot (Jira)

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

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

                Author: ASF GitHub Bot
            Created on: 21/Aug/19 16:27
            Start Date: 21/Aug/19 16:27
    Worklog Time Spent: 10m
      Work Description: verhas commented on issue #444: LANG-1478
URL: https://github.com/apache/commons-lang/pull/444#issuecomment-523537378
 
 
   branched off from a brach... ops...
 
----------------------------------------------------------------
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:
[hidden email]


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

    Worklog Id:     (was: 298830)
    Time Spent: 20m  (was: 10m)

> ClassUtils getAbbreviatedName uses len one character shorter
> ------------------------------------------------------------
>
>                 Key: LANG-1478
>                 URL: https://issues.apache.org/jira/browse/LANG-1478
>             Project: Commons Lang
>          Issue Type: Bug
>            Reporter: Peter Verhas
>            Priority: Minor
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> The {{ClassUtils}} method {{getAbbreviatedName}} calculates the required lenght one character short. That way
> {code}
> final String ANY_CLASS_FULL_NAME = "....";
> assertEquals("ANY_CLASS_FULL_NAME ", ClassUtils.getAbbreviatedName(ANY_CLASS_FULL_NAME , ANY_CLASS_FULL_NAME .length()));
> {code}
> will abbreviate the class name, although we are asking exactly the same number of characters as they are there. The solution is that
> {code}
> if (availableSpace > 0) {
> {code}
> has to be modified to
> {code}
> if (availableSpace >= 0) {
> {code}
> 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.



--
This message was sent by Atlassian Jira
(v8.3.2#803003)