You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class RefactorBug {
private ArrayList list = null;
public void updateBug() {
if (list == null) {
list = new ArrayList<>();
}
int index = 0;
while (index < list.size()) {
Object it = list.get(index++);
}
}
}`
In the old days e.g. Eclipse 4.10, selecting the first "list" within the "if" and refactoring to extract a local variable used to extract the variable "list2"
`import java.util.ArrayList;
public class RefactorBug {
private ArrayList list = null;
public void updateBug() {
ArrayList<Object> list2 = list;
if (list2 == null) {
list = new ArrayList<>();
}
int index = 0;
while (index < list2.size()) {
Object it = list2.get(index++);
}
}
}`
There was a warning about changed assign semantics that was easily fixed by changing the new assignment to "list2 = list = ..."
Now e.g 2024-12 the same warning is given and the following bad code is produced
`import java.util.ArrayList;
public class RefactorBug {
private ArrayList list = null;
public void updateBug() {
ArrayList<Object> list2 = list;
if (list2 == null) {
list = new ArrayList<>();
}
int index = 0;
ArrayList<Object> list22 = list;
while (index < list22.size()) {
Object it = list22.get(index++);
}
}
}`
The same "list2 = list = ..." fixup is possible but the gratuitous extra "list22" variable makes the flow needlessly hard to follow.
Please remove the gratuitous variable and correct the assignment from the outset.
The text was updated successfully, but these errors were encountered:
jukzi
transferred this issue from eclipse-jdt/eclipse.jdt.core
Jan 6, 2025
@ewillink please edit the issue such that the whole sources are in text blocks. It would also help if you add comments to the source code where exactly you have the (which?) issue.
The whole sources are in text (paired single quotes). Unfortunately GitHub rendering seems deficient. If I put in more single quotes to 'look' better you won't be able to cut and paste in one go. The example is so short, surely the deficiencies are obvious?
In the following example
`import java.util.ArrayList;
public class RefactorBug {
private ArrayList list = null;
}`
In the old days e.g. Eclipse 4.10, selecting the first "list" within the "if" and refactoring to extract a local variable used to extract the variable "list2"
`import java.util.ArrayList;
public class RefactorBug {
private ArrayList list = null;
}`
There was a warning about changed assign semantics that was easily fixed by changing the new assignment to "list2 = list = ..."
Now e.g 2024-12 the same warning is given and the following bad code is produced
`import java.util.ArrayList;
public class RefactorBug {
private ArrayList list = null;
}`
The same "list2 = list = ..." fixup is possible but the gratuitous extra "list22" variable makes the flow needlessly hard to follow.
Please remove the gratuitous variable and correct the assignment from the outset.
The text was updated successfully, but these errors were encountered: