Maksym Korshun created LANG-1833:
------------------------------------
Summary: FastDateParser throws StringIndexOutOfBoundsException for
invalid ParsePosition
Key: LANG-1833
URL: https://issues.apache.org/jira/browse/LANG-1833
Project: Commons Lang
Issue Type: Bug
Components: lang.time.*
Reporter: Maksym Korshun
FastDateParser does not consistently handle ParsePosition values that exceed
the input length.
The ParsePosition-based parse methods are documented
([javadoc|https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/time/DateParser.html#parse(java.lang.String,java.text.ParsePosition)])
to return null or false
for the Calendar overload and update the ParsePosition on parse failure.
However, when the starting index is greater than the input length, some parsing
strategies(Literal, Textual) throw StringIndexOutOfBoundsException instead.
Example:
{code:java}
ParsePosition pos = new ParsePosition(10);
DateParser parser = FastDateFormat.getInstance("MMM");
parser.parse("Jan", pos);{code}
Current behavior:
* throws StringIndexOutOfBoundsException
Expected behavior:
- returns null
- leaves ParsePosition.index unchanged
- sets ParsePosition.errorIndex to the starting index
The behavior currently depends on the parsing pattern. For example:
- "MMM" throws StringIndexOutOfBoundsException
- 'x' throws StringIndexOutOfBoundsException
- "yyyy" correctly reports parse failure
--
This message was sent by Atlassian Jira
(v8.20.10#820010)