JDK-8081794 : ParsePosition getErrorIndex returns 0 for TimeZone parsing problem
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 8u45,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2015-06-02
  • Updated: 2016-08-24
  • Resolved: 2015-10-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8 JDK 9
7u95Fixed 8u72Fixed 9 b85Fixed
Description
FULL PRODUCT VERSION :
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
DarwinMacBook-Pro-7.local 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
reporting on behalf a Stack Overflow user:
http://stackoverflow.com/questions/30076349/simpledateformat-parse-returns-errorindex-as-0

a malformed TimeZone will prevent parsing the date, but not set the correct errorIndex in ParsePosition

REGRESSION.  Last worked in version 6u43

ADDITIONAL REGRESSION INFORMATION: 
claimed to be working in at least jdk1.6.0_38

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the attach source code

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
parse position for error should be 21
ACTUAL -
parse position for error is 0, the date was not parsed. Provind for example an invalid month name does produce a correct error position of 3

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
  public static void main(String[] args) throws Exception {
    String date = "13 Jan 2005 21:45:34 ABC";
    String format = "dd MMM yyyy HH:mm:ss z";
    ParsePosition pp = new ParsePosition(0);
    pp.setIndex(0);
    SimpleDateFormat sd = new SimpleDateFormat(format, Locale.ENGLISH);
    Date d = sd.parse(date, pp);
    System.out.println(d);
    System.out.println("Error Index " + pp.getErrorIndex());
  }
---------- END SOURCE ----------


Comments
subParseZoneString functions should return "-start" at the end instead of current return value of 0. This will automatically allow "pos.index=-i" set the correct value for errorIndex update.
30-09-2015

1) Run the attached test case (timeparse.java) 2) Checked this with JDK 6u45, 8, 8u45, 8u60 ea b17, and 9 ea b66 in Windows 7 and MAC OS X. 6u45: OK 8: FAIL 8u45: FAIL 8u60 ea b17: FAIL 9 ea b66: FAIL 3) Output (with JDK 6u45): > java timeparse null Error Index 21 Output (with JDK 8u45): > java timeparse null Error Index 0 4) Conclusion: This issue is reproducible with JDK 8-all and 9 ea b66.
03-06-2015