Hi there,
according to the rule squid:S2175 (Inappropriate "Collection" calls should not be made) the following code should raise an issue:
Map<MyType, String> myMap = new HashMap<>();
String value = myMap.get(new UnrelatedType());
Obviously myMap will never contain any element of type UnrelatedType because the keys are of type MyType.
SonarQube (v. 5.3) does not raise this issue here.
Neither does it with a Map:
List<MyType> myList = new ArrayList<>();
boolean contains = myList.contains(new UnrelatedType());
myList.remove(new UnrelatedType());
The documentation of the rule even states explicitly this example:
List<String> list = new ArrayList<String>();
Integer integer = Integer.valueOf(1);
if (list.contains(integer)) { // Noncompliant. Always false.
list.remove(integer); // Noncompliant. list.add(integer) doesn't compile, so this will always return false
}
The Profile SonarWay is activate for this project.
What might be going wrong here?
Thank you very much for your help.
Regards, Simon