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

Bug 322700

Summary: [extract local] "Extract to local variable (replace all occurrences)" is too aggressive
Product: [Eclipse Project] JDT Reporter: Roland Illig <roland.illig>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, srikanth_sankaran
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Roland Illig CLA 2010-08-14 01:22:06 EDT
Build Identifier: 20100218-1602

When replacing all occurrences of a (syntactically) common subexpression, Eclipse doesn't check whether some of the subexpressions are modified meanwhile in an obvious way.

package de.roland_illig.eclipse.bugs;

public class RefactorCommonExpressions {

  public static void main(String[] args) {
    int i = 1;
    System.out.println(i + 1);
    i++;
    System.out.println(i + 1);
  }
}

When I tell Eclipse to refactor the expression "i + 1", it doesn't notice that i is modified in between. This changes the program output from "2 3" to "2 2".

Reproducible: Always
Comment 1 Srikanth Sankaran CLA 2010-08-14 06:57:47 EDT
Move to JDT/UI for comment.
Comment 2 Dani Megert CLA 2010-08-18 02:55:25 EDT

*** This bug has been marked as a duplicate of bug 27740 ***