Name: tb29552 Date: 07/29/97
Conditions within a decision point are not being evaluated
properly when used with an explicit true.
For example, look at the following block of code:
public class bar {
static char g;
public static void main( String argv[] ) {
g = ( foo() || true )? 'g' : 'G';
}
private static boolean foo() {
System.out.println( "In foo" );
return true;
}
}
When compiled and run, this code should reach the ternary,
evaluate the condition by first evaluating the method foo(),
which would in turn print a message and return true. Since
it returns true and a short-circuiting operator OR is used,
the explicit true should not be evaluated and the decision
point should be true.
However, this DOES NOT HAPPEN.
Rather, what happens is the method foo() is never evaluated
and the condition is short-circuited to the right and the
decision point is true.
The important side effect here is conditional evaluation is
supposed to be left to right and by not evaluating the left
condition as expected (and guaranteed by the language spec),
nasty side effects can occur.
Please fix.
Please advise : ###@###.###
company - RST , email - ###@###.###
======================================================================
- duplicates
-
JDK-4053506 JLS violation: (a() || true) cannot be optimized if a() raises Exception
- Closed