Sponsored Link •
There is a serious error in the JDK 1.5 compiler, pointed out to me by one of my readers, Amotz Anner. Using final local variables in conjunction with ternary if-else where one side of the values is null, leads to incorrect results.
There is a serious error in the JDK 1.5 compiler, pointed out to me by one of my readers (of The Java Specialists' Newsletter), Amotz Anner.
Amotz has submitted a bug report already to Sun, and as soon as we have a number from Sun (may take up to three weeks) we will post that in a follow-up.
Here is the problem:
final String name = false ? "Heinz" : null; System.out.println(name);
When compiled using the JDK 1.5 compiler, it will print out "Heinz". It does not matter whether you say -source 1. or whether you run it using any of the JDK 1..x JVMs from Sun.
This happens only when the local variable is set to "final" and one of the values of the ternary if-else is literal null.
PLEASE let's not make this into a mud-slinging match against Sun Microsystems, ok? They are overloaded with bug reports as it is. The reason that I post this is to make you aware to NOT use the final local variables in combination with ternary if-else.
|Heinz Kabutz enjoys driving Java to the limits, and then a bit beyond. He has been programming in Java since 1997 on several very unimportant projects. During that time, he has picked up some horrifying tips on how you can get the most out of Java. These are published on his bi-monthly "The Java(tm) Specialists' Newsletter" (http://www.javaspecialists.co.za). It is not for the uninitiated :-) Heinz received a PhD in Computer Science from the University of CapeTown. He loves living in South Africa as it is both beautiful and interesting. Professionally, Heinz survives by writing Java code, insulting, ahem, consulting, and presenting courses on Java and Design Patterns.|