Which rule? S1319: The type should be an interface such as “Set” rather than the implementation “EnumSet”
Why do you believe it’s a false-positive/false-negative? EnumSet has some specialised methods, which do not exist on any interface.
Are you using
SonarQube Server / Community Build - which version? v10.6 (92116)
How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)
public enum Fruit {
APPLE,
BANANA,
ORANGE,
PEAR;
// triggers here
public static final EnumSet<Fruit> TASTY_FRUIT = EnumSet.of(APPLE, ORANGE, PEAR);
}
// -- in another class
public class AnotherClass {
public static Stream<Fruit> nastyFruitStream() {
// not possible with just a Set<Fruit> because
// enum-specific logic is required to find the compliment
return EnumSet.complementOf(Fruit.TASTY_FRUIT).stream();
}
}