[never 3 dec 96]
In cases where the compiler can confirm that the result of an || is true it doesn't evaluate the || properly, as in "if (foo() || true)" in which the call to foo is never evaluated. I found this on a web page at http://www.cs.arizona.edu/sumatra/hallofshame/opt-if-bug.html. They give an example but I have a shorter one. The following snippet of code prints test2 instead of throwing an exception.
class test {
static boolean foo() throws Exception {
throw new Exception();
}
static public void main(String argv[]) throws Exception {
if (foo() || true) {
System.out.println("test2");
}
}
}
This happens irrespective of whether you pass -g or -O when you compile it.
In cases where the compiler can confirm that the result of an || is true it doesn't evaluate the || properly, as in "if (foo() || true)" in which the call to foo is never evaluated. I found this on a web page at http://www.cs.arizona.edu/sumatra/hallofshame/opt-if-bug.html. They give an example but I have a shorter one. The following snippet of code prints test2 instead of throwing an exception.
class test {
static boolean foo() throws Exception {
throw new Exception();
}
static public void main(String argv[]) throws Exception {
if (foo() || true) {
System.out.println("test2");
}
}
}
This happens irrespective of whether you pass -g or -O when you compile it.
- duplicates
-
JDK-4053506 JLS violation: (a() || true) cannot be optimized if a() raises Exception
- Closed