Bug 38362

Summary: Inconsistent output when using comparrisson operators
Product: [Eclipse Project] JDT Reporter: Bruce Haefele <bruce.haefele>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: minor    
Priority: P3    
Version: 2.1   
Target Milestone: 3.0 M1   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Bruce Haefele CLA 2003-06-03 09:43:29 EDT
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
Comment 1 Rafael Chaves CLA 2003-06-03 11:12:00 EDT
Moving to JDT-Core.
Comment 2 Philipe Mulet CLA 2003-06-04 05:02:37 EDT
Reproduced. It works ok if using the operator '||' instead.
Comment 3 Philipe Mulet CLA 2003-06-04 06:25:20 EDT
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");
	}
Comment 4 David Audel CLA 2003-06-06 08:54:06 EDT
Verified.