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.
Lets have method: Collection foo(int i) { if (i++ > 0) return new HashSet<Integer>(Arrays.asList(i)); else { return Collections.EMPTY_LIST; } } If you apply introduce variable on 'Arrays.asList(i)' the converted code will be: Collection foo(int i) { final List<Integer> asList = Arrays.asList(i); if (i++ > 0) return new HashSet<Integer>(asList); else { return Collections.EMPTY_LIST; } } which changes behaviour. I think that curly brackets should be added to properly introduce variable: Collection foo(int i) { if (i++ > 0) { final List<Integer> asList = Arrays.asList(i); return new HashSet<Integer>(asList); } else { return Collections.EMPTY_LIST; } }
One additional example of strange introduce variable behaviour: Collection<String> getCountries(boolean convertToSet) { if (convertToSet) { Arrays.asList(Locale.getISOCountries()); // Cursor at position of asList return new HashSet<String>(); } else return Arrays.asList(Locale.getISOCountries()); } If I apply Introduce variable on expression Arrays.asList(Locale.getISOCountries()) with Replace All Occurences(2) checked, the result is: Collection<String> getCountries(boolean convertToSet) { List<String> asList = Arrays.asList(Locale.getISOCountries()); // Cursor on this line if (convertToSet) { Arrays.asList(Locale.getISOCountries()); // Cursor on this line return new HashSet<String>(); } else return asList; } Only one replacement has been performed, I would expect 2.
Cannot reproduce any of the examples on the current dev builds.