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

API: SimpleDateFormat.parse throws StringIndexOutOfBoundException w/ GMT+0100

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0, 1.3.0, 1.3.0_02
    • core-libs
    • generic, x86
    • generic, windows_nt, windows_2000



      Name: gsC80088 Date: 02/16/99


      Maybe related to: 4106807, 4029994

      To reproduce, compile and run this application:

      /* SOURCE */
      import java.text.*;
      import java.util.*;

      public class DateParser {

      public DateParser() {
      DateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");

      try {
      Date myDate = formatter.parse("Fri, 31 Dec 1999 00:00:00 GMT+0100");
      System.out.println("Date is: " + myDate);
      } catch(ParseException pe2) {
      System.out.println("ParseException");
      }
      }

      public static void main (String[] args) {
      new DateParser();
      }
      }
      /* END SOURCE */

      /* OUTPUT */
      Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
      ex out of range: 34
              at java.lang.String.charAt(Compiled Code)
              at java.text.SimpleDateFormat.subParse(Compiled Code)
              at java.text.SimpleDateFormat.parse(Compiled Code)
              at java.text.DateFormat.parse(Compiled Code)
              at DateParser.<init>(Compiled Code)
              at DateParser.main(Compiled Code)
      /* END OUTPUT */

      I think that in the current implementation of SimpleDateFormat, a ParseException would have been thrown
      if this bug had not existed.

      However, it may be advisable to make the format of the timezone specification user-definable too.
      (Review ID: 52227)
      ======================================================================

            okutsu Masayoshi Okutsu
            gstone Greg Stone
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: