Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8081794

ParsePosition getErrorIndex returns 0 for TimeZone parsing problem

    Details

    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b85
    • CPU:
      x86
    • OS:
      os_x
    • Verification:
      Verified

      Backports

        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 ----------

          Activity

          Hide
          pardesha Pardeep Sharma added a comment -
          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.
          Show
          pardesha Pardeep Sharma added a comment - 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.
          Hide
          nkumar Naveen Kumar (Inactive) added a comment -
          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.
          Show
          nkumar Naveen Kumar (Inactive) added a comment - 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.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/2a3c2bd933a5
          User: okutsu
          Date: 2015-10-01 06:18:12 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/2a3c2bd933a5 User: okutsu Date: 2015-10-01 06:18:12 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/2a3c2bd933a5
          User: lana
          Date: 2015-10-07 15:59:02 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/2a3c2bd933a5 User: lana Date: 2015-10-07 15:59:02 +0000

            People

            • Assignee:
              nkumar Naveen Kumar (Inactive)
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: