Community
Participate
Working Groups
I am using the JVM which is distributed with IBM WSDK 5 (The web services development kit) with Eclipse 2.1. The following code produces inconsistent results in Eclipse whether done from a scrapbook page or a normal class with a min method. int y = 5; int x = 2; if ( ( (x>3) && (y==5) ) | true) { System.out.print("true"); } else { System.out.print("false"); } The expected result is "true" as the | operator is true when either of its operands are true. The output though is NOTHING. i.e. it breaks the if else. Single stepping shows that after evaluation, the entire if/else body is skipped. The scrap book page fails to terminate the execution thread, though the class doesn't suffer from the same problem. The workaround is simple - Use the single & operator as the problem seems to be with the short-circuit operator && when the first operand evaluates to false. Compiling and running against the same JVM from the command line produces the correct behaviour. I have tested with other JVM's (Sun's 1.4 and WebSphere Application Server's 5.0.1) from the commmand line and these too succeed, but running from eclipse against these JVM's produces the same output of NOTHING. Regards Bruce
Moving to JDT-Core.
Reproduced. It works ok if using the operator '||' instead.
Bug was in boolean optimized codegen (forgot to use intermediate labels for | and & operators). Fixed. Note that on following code, we generate a bytecode length of 25, where Javac 1.4.2 ends up with a bytecode length of 51. public static void main(String[] args) throws Throwable { int x = 2; int y = 5; if ((((x > 1) && (y == 5)) & false)) { System.out.println("true"); } else { System.out.println("false"); } System.out.println("DONE"); }
Verified.