...I decided to write the code to run the same scenarios under Python-3.1.
Interestingly, for the Java example in Puzzle 3, I obtained a different result than what is mentioned in the book (expected result: 5, actual result: -3) - perhaps due to my recent upgrade to the 64-bit version of Java's 1.6.0-u21 release.
Whereas the Python code returned the correct value...
Curious. One would think that an overflow exception could have been detected and thrown in the Java code by the JVM...
I also noted that the three source code analysis tools I ran against the Java code didn't identify the problem either (PMD, FindBugs, CheckStyle).
While this may seem like a trivial code example, there are real-world disasters that are directly related to this type of subtle bug:
"Flight 501, which took place on June 4, 1996, was the first, and unsuccessful, test flight of the European Ariane 5 expendable launch system. Due to an error in the software design (inadequate protection from integer overflow), the rocket veered off its flight path 37 seconds after launch and was destroyed by its automated self-destruct system when high aerodynamic forces caused the core of the vehicle to disintegrate."
Lecture 22: Software Disasters
Kenneth M. Anderson
Software Methods and Tools
CSCI 3308 - Fall Semester, 2004