Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6763465
Votes 0
Synopsis Issue with TimeStamp.valueOf method of JDK 1.6
Category jdbc:spec
Reported Against
Release Fixed
State 6-Fix Understood, request for enhancement
Priority: 4-Low
Related Bugs
Submit Date 24-OCT-2008
Description
FULL PRODUCT VERSION :
jdk1.6.0_10

ADDITIONAL OS VERSION INFORMATION :
Windows 2003 server

A DESCRIPTION OF THE PROBLEM :
It seems there is an issue with java.sql.TimeStamp class, valueOf() method.
When we execute: Timestamp.valueOf("2008-1-26 12:12:12")

	Sample code:
	public class TimestampTest {
		public static void main(String[] args) {
			Timestamp t = Timestamp.valueOf("2005-1-01 10:20:50.00");
		}
	}

Following exception is received:
Exception in thread "main" java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
	at java.sql.Timestamp.valueOf(Timestamp.java:194)

The Java version I am using is: jdk1.6.0_10.
The above line of code works fine with jdk 1.5 and former versions.

This happens only when we pass single digit in Date/Month parameter. (As in above example "1" is passed as month parameter instead of "01")

In Java 6, in the TimeStamp.java class, there is extra check done for the length of the year, month and day fields and restricting the year to 4, month to 2 and day to 2 characters.

Code snippet from the Timestamp.valueOf method (Java 6)
	int intDate[] = {4,2,2};
	if(tokenDate.length() != intDate[counterD] ) {

Has the above restriction deliberately imposed? This restriction was not there in previous releases. This will result in changes for the code which was relying on the above API.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use following line of code to reproduce the issue with jdk 1.6

	public class TimestampTest {
		public static void main(String[] args) {
			Timestamp t = Timestamp.valueOf("2005-1-01 10:20:50.00");
                        System.out.println(t);
		}
	}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
2008-01-26 12:12:12.0
ACTUAL -
Exception in thread "main" java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
	at java.sql.Timestamp.valueOf(Timestamp.java:194)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
	public class TimestampTest {
		public static void main(String[] args) {
			Timestamp t = Timestamp.valueOf("2005-1-01 10:20:50.00");
                        System.out.println(t);
		}
	}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
use "01" instead of  "1" in the above example.

Release Regression From : 5.0u12
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.
Posted Date : 2008-10-24 09:39:13.0
Work Around
N/A
Evaluation
The change in behavior is intentional and was done as part of the fix for 5006540.

The javadocs are clear that the format is yyyy-mm-dd hh:mm:ss[.f...]

There is nothing in the javadocs which indicates a leading 0 is optional.  Now that being said, I do not have an issue relaxing the format for mm and dd so the leading 0 can be omitted, but not until Java SE 7 and JDBC 4.1 when I can update the javadocs accordingly.

I have changed this to an RFE to the spec.
Posted Date : 2008-10-24 14:49:23.0
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang