diff --git a/its/autoscan/src/test/resources/autoscan/diffs/diff_S4738.json b/its/autoscan/src/test/resources/autoscan/diffs/diff_S4738.json index ac41817e82a..2d78f813b10 100644 --- a/its/autoscan/src/test/resources/autoscan/diffs/diff_S4738.json +++ b/its/autoscan/src/test/resources/autoscan/diffs/diff_S4738.json @@ -1,6 +1,6 @@ { "ruleKey": "S4738", "hasTruePositives": false, - "falseNegatives": 55, + "falseNegatives": 44, "falsePositives": 0 -} \ No newline at end of file +} diff --git a/java-checks-test-sources/default/src/main/files/non-compiling/checks/ReplaceGuavaWithJavaCheck_java9.java b/java-checks-test-sources/default/src/main/files/non-compiling/checks/ReplaceGuavaWithJavaCheck_java9.java index d14fa7c1b5e..74ece8792b5 100644 --- a/java-checks-test-sources/default/src/main/files/non-compiling/checks/ReplaceGuavaWithJavaCheck_java9.java +++ b/java-checks-test-sources/default/src/main/files/non-compiling/checks/ReplaceGuavaWithJavaCheck_java9.java @@ -60,8 +60,8 @@ void tempDir() throws IOException { } void immutableCollections() { - ImmutableSet.of("A", "B", "C"); // Noncompliant {{Use "java.util.Set.of()" instead.}} + ImmutableSet.of("A", "B", "C"); // Compliant, because ImmutableSet.of keeps the order of the elements ImmutableList.of("A", "B", "C"); // Noncompliant {{Use "java.util.List.of()" instead.}} - ImmutableMap.of("A", "B", "C", "D"); // Noncompliant {{Use "java.util.Map.of()" or "java.util.Map.ofEntries()" instead.}} + ImmutableMap.of("A", "B", "C", "D"); // Compliant, because ImmutableMap.of keeps the order of the elements } } diff --git a/java-checks/src/main/java/org/sonar/java/checks/ReplaceGuavaWithJavaCheck.java b/java-checks/src/main/java/org/sonar/java/checks/ReplaceGuavaWithJavaCheck.java index 7d64c230eae..77ae8de7842 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/ReplaceGuavaWithJavaCheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/ReplaceGuavaWithJavaCheck.java @@ -40,9 +40,7 @@ public class ReplaceGuavaWithJavaCheck extends AbstractMethodDetection implement private static final String GUAVA_BASE_ENCODING = "com.google.common.io.BaseEncoding"; private static final String GUAVA_OPTIONAL = "com.google.common.base.Optional"; private static final String GUAVA_FILES = "com.google.common.io.Files"; - private static final String GUAVA_IMMUTABLE_SET = "com.google.common.collect.ImmutableSet"; private static final String GUAVA_IMMUTABLE_LIST = "com.google.common.collect.ImmutableList"; - private static final String GUAVA_IMMUTABLE_MAP = "com.google.common.collect.ImmutableMap"; private static final Map GUAVA_TO_JAVA_UTIL_TYPES = MapBuilder.newMap() .put("com.google.common.base.Predicate", "java.util.function.Predicate") @@ -69,7 +67,7 @@ protected MethodMatchers getMethodInvocationMatchers() { MethodMatchers.create().ofTypes(GUAVA_OPTIONAL).names("absent").addWithoutParametersMatcher().build(), MethodMatchers.create().ofTypes(GUAVA_OPTIONAL).names("fromNullable", "of").withAnyParameters().build(), MethodMatchers.create().ofTypes(GUAVA_FILES).names("createTempDir").addWithoutParametersMatcher().build(), - MethodMatchers.create().ofTypes(GUAVA_IMMUTABLE_LIST, GUAVA_IMMUTABLE_SET, GUAVA_IMMUTABLE_MAP) + MethodMatchers.create().ofTypes(GUAVA_IMMUTABLE_LIST) .names("of").withAnyParameters().build()); } @@ -111,12 +109,6 @@ protected void onMethodInvocationFound(MethodInvocationTree mit) { case GUAVA_IMMUTABLE_LIST: reportJava9Issue(mit, "java.util.List.of()"); break; - case GUAVA_IMMUTABLE_SET: - reportJava9Issue(mit, "java.util.Set.of()"); - break; - case GUAVA_IMMUTABLE_MAP: - reportJava9Issue(mit, "java.util.Map.of()\" or \"java.util.Map.ofEntries()"); - break; default: break; }