This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 223935 - [rename-refactoring] NB silently renames a variable inside a inner block to a name of an existent one outside
Summary: [rename-refactoring] NB silently renames a variable inside a inner block to a...
Status: REOPENED
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Model (show other bugs)
Version: 7.2.1
Hardware: All All
: P3 normal (vote)
Assignee: Vladimir Voskresensky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-17 14:26 UTC by gugawag
Modified: 2014-11-19 13:47 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description gugawag 2012-12-17 14:26:05 UTC
Build: 201210100934 (Same result in NB 7.3 Beta 2 Build 201211062253)

NB refactoring support renames a variable inside a inner block to a name of an existent one outside this block, leading to a behavioral change of the app.

Reproducible: Always

Steps to Reproduce:

1. Create a C file with the following code:

#include <stdio.h>
int main(void){
    int two = 2;
    {
       int three = 3;
       printf("%d", two);
    }
    return 0;
}

obs.: output of this program: 2

2. Apply the rename to the "three" variable inside the inner block, typing in the New Name "two" (NB silently do that):

#include <stdio.h>
int main(void){
    int two = 2;
    {
       int two = 3;
       printf("%d", two);
    }
    return 0;
}

3. The program change its output: from 2 to 3
Comment 1 gugawag 2012-12-17 14:35:38 UTC
Its reproducible in any inner block, like switch, for example:

1 -

#include <stdio.h>

int main(void){
        int i = 2;
        int two = 2;
	switch(i){
                int three = 3;
		case 1: {
                        printf("%d", 1);
			break;
		}
		case 2: {
			printf("%d", two);
			break;
		}
	}
	return 0;
}

output: 2

2 - rename the three variable inside switch block to "two":

#include <stdio.h>

int main(void){
        int i = 2;
        int two = 2;
	switch(i){
                int two = 3; //refactored
		case 1: {
                        printf("%d", 1);
			break;
		}
		case 2: {
			printf("%d", two);
			break;
		}
	}
	return 0;
}


new output: 3
Comment 2 Ondrej Vrabec 2012-12-17 15:30:43 UTC
please do not file cnd-related stuff on apisupport product but cnd instead
Comment 3 Leonid Lenyashin 2012-12-17 15:47:44 UTC
Please describe expected behavior. The functionality works as designed.
Comment 4 gugawag 2012-12-17 17:10:34 UTC
Dear Leonid.

  By the refactoring theory, any type of transformation that refactoring tools do in a code has to maintain the behavior of this code. In the case of this issue, NB change the variable name and the output of the program changed from 2 to 3, what is considered a bug by the refactoring point of view.
 
In this case, NB must prevent to do this transformation.
Comment 5 gugawag 2012-12-17 20:21:19 UTC
Eclipse CDT does not allow this refactoring, since there is another variable with the same name and this transformation could lead to a behavioral change (it cannot be done in refactoring theory). 

See Eclipse CDT images attached. In the first one, it informs that there is a conflict. Even so, the user can click preview (image 2) and performs the refactoring. But, at least, eclipse informed the user about the possible issue.