java.sql.Date.valueOf() : comparing Sun vs BEA jRockit JVM

I've noticed two different behaviour of the static method java.sql.Date.valueOf() using Sun JVM instead of BEA jRockit JVM. I share with you this experience.

If you have the following string:

String myStringDate = "2010-01-010";

and apply the above method to get a java.sql.Date from it, as follows:

java.sql.Date date = java.sql.Date.valueOf(myStringDate);

on both Sun and BEA jRockit JVM, the method works fine and return a date.

BUT, if the string date is formatted like this

String myStringDate = "2010-1-10"; //note the month without zero.

 and apply the above method to get a java.sql.Date from it, as follows:

 java.sql.Date date = java.sql.Date.valueOf(myStringDate);

on Sun JVM (i've tried with 1.6 version) , you get the following exception

Exception in thread "main" java.lang.IllegalArgumentException
    at java.sql.Date.valueOf(Unknown Source)

while, using jRockit still works fine. So, pay attention in get date from string using this method, if you don't know on  which JVM your code will be run.

Hope this can be helpful.

0 commenti: