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

java.sql.Date.valueOf no exception if date given is not in the JDBC date escape format(yyyy-mm-dd)

XMLWordPrintable

    • 1.1
    • 1.1
    • b09
    • x86
    • windows_xp
    • Verified

        As per the API doc for java.sql.Date.valueOf, IllegalArgumentException should
        be thrown if the date given is not in the JDBC date escape format
        (yyyy-mm-dd).
         
        The error is not thrown when I enter the value '20009-10-10'. Instead it
        silently stores the value. But later when I do java.sql.toString()
         
            public static void main(String[] args) {
                java.sql.Date jsd = java.sql.Date.valueOf("20009-06-26");
                System.out.println(jsd);
         
            }



         
        The above program prints
        *009-06-26 Where '*' is a non-readable character.

        We need fix in valueOf method() to throw the exception if we pass 5 digits to
        the API.

        From API
        valueOf

        public static Date valueOf(String s)

            Converts a string in JDBC date escape format to a Date value.

            Parameters:
                s - a String object representing a date in in the format "yyyy-mm-dd"
            Returns:
                a java.sql.Date object representing the given date
            Throws:
                IllegalArgumentException - if the date given is not in the JDBC date escape format (yyyy-mm-dd)

              minqi Yumin Qi
              dvanero Dennis Van Eron (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: