| Summary: | [inline] Inline refactoring on boolean OR-expression results in wrong code | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Martin Hanzalek <martin.hanzalek> |
| Component: | UI | Assignee: | 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: | |||
Thanks for the report Martin. Moving to JDT/UI. 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 *** *** This bug has been marked as a duplicate of bug 405096 *** Cannot reproduce using 4.3 M6. |
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'.