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.
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.