JDK-5006540 : java.sql.Timestamp.valueOf(String) fails to throw an IllegalArgumentException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.sql
  • Affected Version: 1.4.2,6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS:
    generic,solaris_10,windows_2000,windows_xp generic,solaris_10,windows_2000,windows_xp
  • CPU: generic,x86,sparc
  • Submitted: 2004-03-02
  • Updated: 2017-05-16
  • Resolved: 2008-01-10
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 6
6 b78Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Description
Name: rmT116609			Date: 03/02/2004


FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)


FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
According to the API documents of above JDK versions, the static method java.sql.Timestamp.valueOf() should take only JDBC timestamp escape format which is yyyy-mm-dd hh:mm:ss.fffffffff. It throws an IllegalArgumentException if the given argument does not have the format yyyy-mm-dd hh:mm:ss.fffffffff.

In my test with the above versions, I used an invalid argument format "05-2003-02 0:0:0.0". The expected IllegalArgumentException was not thrown. Instead, the invalid argument was converted to a Timestamp with a String value equals "0171-11-02 00:00:00.0" under JDK version "1.4.1_01" and "171-11-02 00:00:00.0" under JDK version "1.3.1_06".



STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the source code provided below and run under either JDK version "1.4.1_01" or JDK version "1.3.1_06".


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An IllegalArgumentException is expected to be thrown.
ACTUAL -
The invalid argument used was converted to a Timestamp with a String value equals "0171-11-02 00:00:00.0" under JDK version "1.4.1_01" and "171-11-02 00:00:00.0" under JDK version "1.3.1_06".


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class TestTimestamp {
	public static void main(java.lang.String[] args) {
		System.out.println(java.sql.Timestamp.valueOf("05-2003-02 0:0:0.0"));
	}
}

---------- END SOURCE ----------
(Incident Review ID: 190668) 
======================================================================

Comments
EVALUATION This is strange situation to be in. The fix passes with Derby but fails with Pointbase. It can be that Pointbase doesn't adhere exactly to the spec and at the same time we were not validating the Timestamp string properly. I have kept the checks for year but have removed the checks for time i.e. checks for yyyy-mm-dd are there but checks for hh:mm:ss.fffffffff have been removed. This removal of check should ensure all are fine. But as of now this is the final check unless verification fails. After verification, I will close this.
27-03-2006

EVALUATION This is being re opened, the behaviour of f's was mandated to be one or more f's now it has been loosened again to 0 or more f's.
02-01-2006

EVALUATION More checks have been added to check that the String argument if of format yyyy-mm-dd hh:mm:ss.fffffffff. These checks were earlier missing. Now if the string value is of format e.g. yyyy-mm-dd hh:mm:ss.ffffffff i.e. one 'f' less it will throw IllegalArgumentException It has to be of exactly the same format, if 0's need to be appended or pre pended they should be appropriately done to match the format. *** (#1 of 1): [ UNSAVED ] ###@###.###
15-11-2005