commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita (JIRA)" <>
Subject [jira] [Commented] (LANG-1327) org.apache.commons.lang3.time.DateFormatUtils.formatUTC (10L, "") throws java.lang.StringIndexOutOfBoundsException exception
Date Wed, 03 May 2017 05:37:04 GMT


Bruno P. Kinoshita commented on LANG-1327:

(was writing probably at the same time [~chonton] closed the issue. Agree with his comment,
but will leave mine here too FWIW)

Looks like that changed indeed from 3.4 to 3.5, but not in DateFormatUtils, but in FastDatePrinter.

{noformat}git diff LANG_3_4 master src/main/java/org/apache/commons/lang3/time/{noformat}

Instead of simply calling the format method, now it's checking which rules it can apply, and
in your case not applying anything, and simply returning an empty String.

Adding a note to DateFormatUtils#format(Long, String) for that, would mean adding a note to
all other methods that receive a pattern argument iff the behaviour is consistent (i.e. if
for all these methods, passing an empty pattern, returns an empty string). However, I would
argue that it would make more sense to document an exception, such as StringIndexOutOfBoundsException,
rather than document that we won't throw an exception, and instead will return empty.

Passing an empty pattern, users might guess that they will receive an empty date. I would
be fine if the consensus was to document all methods stating that an empty pattern will return
an empty formatted date but, my preferred solution is to close this as Won't Fix. 

> org.apache.commons.lang3.time.DateFormatUtils.formatUTC (10L, "") throws java.lang.StringIndexOutOfBoundsException
> ----------------------------------------------------------------------------------------------------------------------------
>                 Key: LANG-1327
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.4, 3.5
>         Environment: JRE 8
>            Reporter: Gleison Brito Batista
> I am calling method formatUTC() of class
> org.apache.commons.lang3.time.DateFormatUtils
> as in this code:
> java.lang.String var2 = org.apache.commons.lang3.time.DateFormatUtils.formatUTC (10L,
> In version 3.4, the call is throwing a
> java.lang.StringIndexOutOfBoundsException exception.
> But in version 3.5 it returns an empty string ("").
> According the documentation, the parameter patter can not be null.
> Is correct this method accept empty string as pattern parameter?

This message was sent by Atlassian JIRA

View raw message