Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromParameter/beforeFieldAlreadyExistsAndAssigned.java
Bartek Pacia eb4e3aef67 IDEA-383357 [java-intentions] fix 'Create field for parameter' being available when it doesn't make sense
The fix was done in the previous commit, the one that also fixed IDEA-383350.
This commit only adds a test case for the bug described in IDEA-383357

GitOrigin-RevId: 6669cffaca5b10c43779093e9ef672a575e7a13f
2025-12-12 15:39:43 +00:00

23 lines
622 B
Java

// "Create field for parameter 'hobbies'" "false"
import java.util.Collections;
import java.util.LinkedHashSet;
class Person {
String name;
int age;
private final String[] hobbies;
Person(String name, int age, String... <caret>hobbies) {
this.name = name;
this.age = age;
LinkedHashSet hobbySet = new LinkedHashSet<>();
Collections.addAll(hobbySet, hobbies);
if (hobbies.length == 0) {
throw new IllegalArgumentException("Interesting person must have at least one hobby.");
}
this.hobbies = hobbySet.toArray(new String[hobbySet.size()]);
System.out.println(hobbies);
}
}