Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 386028

Summary: [inline] Inline refactoring on boolean OR-expression results in wrong code
Product: [Eclipse Project] JDT Reporter: Martin Hanzalek <martin.hanzalek>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, daniel_megert, deepakazad, martin.hanzalek
Version: 4.2   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Martin Hanzalek CLA 2012-07-26 07:35:58 EDT
Build Identifier: Version: Indigo Service Release 2 Build id: 20120216-1857

Inline operation on boolean expression 'a || b' doesn't put parenthesis around, so it can result in wrong code. Example:

		boolean a = true;
		boolean b = true;
		boolean c = false;
		boolean a_or_b = a || b;

		// should resolve to false, but after inline operation on 'a_or_b' variable resolves to true
		if (a_or_b && c)
			System.out.println("Error");
		else
			System.out.println("OK");

After inlining a_or_b produces code:

		if (a || b && c)
			System.out.println("Error");
		else
			System.out.println("OK");

instead of ((a || b) && c), which is wrong.

This can lead to a wrong code when you trust refactoring tools and do not check the result.

Reproducible: Always

Steps to Reproduce:
1. Run code:

public class Main {
	public static void main(String[] args) {
		boolean a = true;
		boolean b = true;
		boolean c = false;
		boolean a_or_b = a || b;

		// should resolve to false, but after inline operation on 'a_or_b' variable resolves to true
		if (a_or_b && c)
			System.out.println("Error");
		else
			System.out.println("OK");
	}
}
Should print 'OK'.

2. Run inline operation on a_or_b expression

3. run code again, prints 'Error'.
Comment 1 Ayushman Jain CLA 2012-07-26 07:40:00 EDT
Thanks for the report Martin.
Moving to JDT/UI.
Comment 2 Deepak Azad CLA 2012-07-26 08:08:54 EDT
Most likely the same fix as bug 337680. In any case they need to be investigated together.

*** This bug has been marked as a duplicate of bug 337680 ***
Comment 3 Dani Megert CLA 2013-04-11 05:52:57 EDT

*** This bug has been marked as a duplicate of bug 405096 ***
Comment 4 Dani Megert CLA 2013-04-11 06:01:01 EDT
Cannot reproduce using 4.3 M6.