Bug 567617

Summary: [cleanup] "Raise embedded if into parent if" cleanup crashes with double lone ifs with ending comment
Product: [Eclipse Project] JDT Reporter: Fabrice Tiercelin <fabrice.tiercelin>
Component: UIAssignee: Fabrice Tiercelin <fabrice.tiercelin>
Status: VERIFIED FIXED QA Contact: Carsten Hammer <carsten.hammer>
Severity: normal    
Priority: P3    
Version: 4.17   
Target Milestone: 4.18 M3   
Hardware: All   
OS: All   
See Also: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/171577
https://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/commit/?id=e47bcb5fd414abcd2cf5a7b765dc8f01c398e8cf
Whiteboard:
Bug Depends on: 566870    
Bug Blocks:    

Description Fabrice Tiercelin CLA 2020-10-05 17:23:51 EDT
We have a bug for double lone ifs:

Given:
if (isActive)
    if (isValid)
        int i = 0;

When:
Clean up the code enabling "Raise embeded if into parent if"

Expected:
if (isActive && isValid)
    int i = 0;

Actual:
org.eclipse.text.edits.MalformedTreeException: Range of child edit lies outside of parent edit
Comment 1 Fabrice Tiercelin CLA 2020-10-07 08:39:12 EDT
Actually, it is not due to the lone statement, it is due to an ending comment:

if (isActive)
    if (isValid)
        int i = 0; // foo
Comment 2 Fabrice Tiercelin CLA 2020-10-27 01:09:27 EDT
This can be fixed when cleanup will be multi-pass. This is planned: Bug 566870.

The idea is that when we encounter two embedded lone if statements, we only add bracket to the parent if. Doing this, the second pass will correctly cleanup the code (without bracket). So the code will be cleanup in two passes.
Comment 3 Eclipse Genie CLA 2020-11-01 07:48:36 EST
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/171577
Comment 5 Fabrice Tiercelin CLA 2020-11-21 03:39:55 EST
Verified for 4.18M3 using I20201116-1800 build