You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Avijit Chakraborty (Jira)" <ji...@apache.org> on 2020/12/19 16:56:00 UTC

[jira] [Comment Edited] (LANG-1629) DurationFormatUtils.formatPeriod is infinite repetition when parameter is negative number

    [ https://issues.apache.org/jira/browse/LANG-1629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17252222#comment-17252222 ] 

Avijit Chakraborty edited comment on LANG-1629 at 12/19/20, 4:55 PM:
---------------------------------------------------------------------

Hi [~helloJuhyun], 

I also tried to reproduce the infinite loop, but unable to do so like [~kinow] .

This below code of yours is causing the existing validation to be failed and I am getting the expected error message "startMillis must not be greater than endMillis"
{code:java}
DurationFormatUtils.formatPeriod(1608377400000, -62170189200000, "HH:mm:ss");{code}
Could you do a recheck and perhaps debug formatPeriod() from your project code to check how it is going to the while loops down the line even if endMillis argument is less than startMillis.

If you are able to find out the reason, I will be happy to know the same, so please share your thoughts.

 


was (Author: aviprogrammer):
Hi [~helloJuhyun], 

I also tried to reproduce the infinite loop, but unable to do so like [~kinow] .

This below code of yours is causing the existing validation to be failed and I am getting the expected error message "startMillis must not be greater than endMillis"
DurationFormatUtils.formatPeriod(1608377400000, -62170189200000, "HH:mm:ss");
Could you do a recheck and perhaps debug formatPeriod() from your project code to check how it is going to the while loops down the line even if endMillis argument is less than startMillis.

If you are able to find out the reason, I will be happy to know the same, so please share your thoughts.

 

> DurationFormatUtils.formatPeriod is infinite repetition when parameter is negative number
> -----------------------------------------------------------------------------------------
>
>                 Key: LANG-1629
>                 URL: https://issues.apache.org/jira/browse/LANG-1629
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.11
>            Reporter: LeeJuHyun
>            Priority: Major
>             Fix For: Discussion
>
>
> if parameter number(*startMillis*, *endMillis*) is negative number then below while loop is infinite repetition. (278 line ~)
> {code:java}
> public static String formatPeriod(final long startMillis, final long endMillis, final String format, final boolean padWithZeros,
>         final TimeZone timezone) {
>     Validate.isTrue(startMillis <= endMillis, "startMillis must not be greater than endMillis");
>     // Used to optimise for differences under 28 days and
>     // called formatDuration(millis, format); however this did not work
>     // over leap years.
>     // TODO: Compare performance to see if anything was lost by
>     // losing this optimisation.
>     final Token[] tokens = lexx(format); 
>     // ...
>     while (start.get(Calendar.YEAR) != target) {
>     days += start.getActualMaximum(Calendar.DAY_OF_YEAR) - start.get(Calendar.DAY_OF_YEAR);
>     // Not sure I grok why this is needed, but the brutal tests show it is
>     if (start instanceof GregorianCalendar &&
>             start.get(Calendar.MONTH) == Calendar.FEBRUARY &&
>             start.get(Calendar.DAY_OF_MONTH) == 29) {
>         days += 1;
>     }
>     start.add(Calendar.YEAR, 1);
>     days += start.get(Calendar.DAY_OF_YEAR);
> }{code}
>  
> How about putting in a validation to determine whether it's negative or positive?
>  
> thank you :)
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)