DongChunHao opened a new issue, #7294:
URL: https://github.com/apache/netbeans/issues/7294
### Apache NetBeans version
Apache NetBeans 21
### What happened
When I select "arrs[a]" and perform the extract local variable refactoring,
the new method name is "localVar", select replaceAll and I click "OK", a syntax
compilation error occurs:
public class OriginalClass {
public void test() {
int[] arrs = {1,2,3};
int a = 0;
// extract variable: arrs[a]
System.out.println(arrs[a]);
a++;
System.out.println(arrs[a]);
a++;
System.out.println(arrs[a]);
}
}
refactoring result:

Due to the change in the value of "a" after each output, the behavior before
and after refactoring is inconsistent.
Expected result: For situations where values change, multiple local
variables should be reset to avoid inconsistent behavior before and after
refactoring.
### Language / Project Type / NetBeans Component
_No response_
### How to reproduce
Perform the following actions on the following code:
selecet “arrs[a]”
click “Refactor-Introduce-variable”
select replace all
new name "localVar"
click “ok”
public class OriginalClass {
public void test() {
int[] arrs = {1,2,3};
int a = 0;
// extract variable: arrs[a]
System.out.println(arrs[a]);
a++;
System.out.println(arrs[a]);
a++;
System.out.println(arrs[a]);
}
}
### Did this work correctly in an earlier version?
No / Don't know
### Operating System
Windows11
### JDK
20
### Apache NetBeans packaging
Apache NetBeans platform
### Anything else
_No response_
### Are you willing to submit a pull request?
No
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists