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

Bug 316372

Summary: [change method signature] Refactor: adding argument to method signature does not check for name clashes with object's instance variables
Product: [Eclipse Project] JDT Reporter: Michael Fairbank <michael.fairbank>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, Olivier_Thomann
Version: 3.7   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Michael Fairbank CLA 2010-06-09 15:59:49 EDT
Build Identifier: 20090920-1017

When you add an argument to a method signature using refactoring, it does not check for name clashes of that argument with existing instance variables of the class.  This causes refactoring to change the behaviour (i.e. introduce bugs to) existing code.

Reproducible: Always

Steps to Reproduce:
1.  Create the short class "Main1" which is pasted below.
2.  Highlight the method "func" and do "refactor: change method signature".  Add an argument of type double, and call it "a".  No default value necessary. 
3.  The bug is that before the refactoring, the line "if (a!=2)..." referred to the instance variable a, but after refactoring it will refer to the local variable a (the argument).  hence this changes the program's functionality: the refactor script should alter the line to "if (Main1.a!=2)...", or produce a warning/error.

This bug also occurs for non static instance variables.

Thank you for an excellent product!

End of bug report (code sample follows)...
public class Main1 {
	final static double a=2;
	public static void func(double b) {
		if (a!=2) throw new RuntimeException();
	}
	
}
Comment 1 Olivier Thomann CLA 2010-06-09 17:09:29 EDT
Moving to JDT/UI
Comment 2 Dani Megert CLA 2010-06-10 08:21:14 EDT

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