Gotchas in JDK 6

Are there any bugs in JDK 6 that were not present in earlier versions? I am interested to know some unexpected changes, for example, the following in the Timestamp.valueOf () method.

Timestamp.valueOf () when there is a timestamp that contains a date or month with a single digit. eg. 2009-9-20, 2009-9-3, 2009-12-4, etc., behaves differently in JDK 6 - it throws an IllegalArgumentException saying that the timestamp is incorrectly formatted. While JDK 5 (and earlier versions) works very well, providing the correct values ​​with "0" prefixing for these single-digit numbers.

JDK 6 is simply more strict because the method really considers the argument to be a string in JDBC escape tag format. However, this BREAKS code is written in JDK 5.

Code:

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

However, JDK 6 works great with hours, minutes, seconds, making up one digit. I found out what was wrong by looking at the source code of the Timestamp class in JDK 6. I found an intDate [] array that is initialized {4,2,2}, and the length of each item in the date is checked for this array.

Now why is part of the time working fine, even if they have separate numbers? Because the code that checks the length for the equivalent array intTime [] is commented out in the source.

The Timestamp class in JDK 5 did not have any of these checks and works great with such inputs.

I do not find such oddities mentioned anywhere on the official website. Although I found another person who has the same problem . This problem is easily fixed, and I'm interested in learning about other such odd changes that have occurred in JDK 6.

+3
1
+7

Source: https://habr.com/ru/post/1720575/


All Articles