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

SimpleDateFormat.parse throws unexpected exception

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.1.4
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Not verified

      Description

      The following program should throw ParseException instead of StringIndexOutOfBoundsException.

      import java.text.*;
      import java.util.*;

      public class selm{
          public static void main(String[] args){
              SimpleDateFormat dateFormat;
              Date date2;
              dateFormat = new SimpleDateFormat("yy/mm/dd HH:mm:ss");
              try{
                  date2 = dateFormat.parse("97/01/17");
                  System.out.println(date2.toString());
              }
              catch(ParseException e){
                  e.printStackTrace();
              }
          }
      }


      java selm
      java.lang.StringIndexOutOfBoundsException: String index out of range: 8
              at java.lang.String.charAt(String.java)
              at java.text.SimpleDateFormat.parse(SimpleDateFormat.java)
              at java.text.DateFormat.parse(DateFormat.java)
              at selm.main(selm.java:10)

        Attachments

          Activity

            People

            Assignee:
            nlindenbsunw Norbert Lindenberg (Inactive)
            Reporter:
            sishidasunw Shoji Ishida (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: