Java – traps in JDK 6

Are there any problems in JDK 6 that do not exist in previous versions? I'm interested in timestamp Some surprising changes are found in the way valueof () works, such as the following

Timestamp. Valueof() provides a timestamp containing a date or month with a single number For example 2009-9-202009-9-3, 2009-12-4, etc., behave differently in JDK 6 - it throws an illegalargumentexception, indicating that the timestamp format is incorrect JDK 5 (and earlier versions) works well, providing the correct values prefixed with '0' of those individual numbers

JDK 6 is just more stringent because the method does think its parameter is a string in JDBC timestamp escape format However, the breaks code is written in JDK 5

Code such as:

String s = "2009-9-1 00:00:00";
Timestamp t = Timestamp.valueOf(s);

However, JDK 6 works well, in hours, minutes and seconds By looking at the source code of timestamp class in JDK 6, I found what is wrong I found an array intdate [], which is initialized to {4,2,2}, and checked the length array of each item in the date against this object

Why do time parts work now, even if they have a single number? Because the code for checking the length and the equivalent array inttime [] is commented out in the source

The timestamp class in JDK 5 does not have any of these checks and can use these inputs normally

I haven't found such a strange place anywhere on the official website Although I found that another person has the same problem This problem is easy to solve. I'm interested in finding other strange changes in JDK 6

Solution

Formal, this

edit

In addition, you can view sun's error database

This link shows the Java type bug, including the acceptance status and the keyword "1.6 1.5"

I checked some. It looks like what you need

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>