We updated the sonar to the latest plugins and now enabled this rule again.
This is generating false-positives in this case:
public interface BaseClass { }
public static class ChildClass implements BaseClass { }
public static Map.Entry<String, BaseClass> provideExample() {
return new AbstractMap.SimpleImmutableEntry<String, BaseClass>("", new ChildClass());
}
When I remove the types as suggested by the issue, I got an error:
Example.java with code provided by you after replacement of <String, BaseClass> on diamond operator <>
import java.util.AbstractMap;
import java.util.Map;
public class Example {
public interface BaseClass { }
public static class ChildClass implements BaseClass { }
public static Map.Entry<String, BaseClass> provideExample() {
return new AbstractMap.SimpleImmutableEntry<>("", new ChildClass());
}
}
compiles just fine with javac11.0.1, 10.0.1, 9.0.4 and 1.8.0_202.
To me seems that it is IntelliJ IDEA on your screenshot (is it?) and AFAIR its old versions had bugs in inference of types. IntelliJ IDEA 2019.1 suggest replacement