Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions its/ruling/src/test/resources/guava/java-S1452.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"com.google.guava:guava:src/com/google/common/base/Enums.java": [
100,
100
],
"com.google.guava:guava:src/com/google/common/cache/CacheBuilder.java": [
767
],
Expand All @@ -16,18 +12,11 @@
513
],
"com.google.guava:guava:src/com/google/common/collect/Maps.java": [
106,
111,
649,
2131,
2135
649
],
"com.google.guava:guava:src/com/google/common/collect/MinMaxPriorityQueue.java": [
903
],
"com.google.guava:guava:src/com/google/common/collect/Ordering.java": [
413
],
"com.google.guava:guava:src/com/google/common/collect/RegularImmutableAsList.java": [
49
],
Expand All @@ -47,16 +36,12 @@
"com.google.guava:guava:src/com/google/common/collect/TreeMultimap.java": [
156
],
"com.google.guava:guava:src/com/google/common/hash/Funnels.java": [
169
],
"com.google.guava:guava:src/com/google/common/reflect/Element.java": [
48
],
"com.google.guava:guava:src/com/google/common/reflect/Invokable.java": [
67,
108,
129
108
],
"com.google.guava:guava:src/com/google/common/reflect/Parameter.java": [
56,
Expand All @@ -67,7 +52,6 @@
157,
238,
275,
315,
364,
387,
562,
Expand Down
3 changes: 0 additions & 3 deletions its/ruling/src/test/resources/sonar-server/java-S1452.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"org.sonarsource.sonarqube:sonar-server:src/main/java/org/sonar/server/computation/task/projectanalysis/qualitygate/EvaluationResult.java": [
46
],
"org.sonarsource.sonarqube:sonar-server:src/main/java/org/sonar/server/computation/task/projectanalysis/step/NewCoverageMeasuresStep.java": [
131
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package checks;

import java.util.List;
import java.util.ArrayList;

public class WildCardReturnParameterNestedTypeSample {
void bar() {
foo(listOfLists());
}

void foo(List<List<? extends A>> listList) {

}

List<List<? extends A>> listOfLists() {
return new ArrayList<>();
}

private static class A {
}

private static class B extends A {
}

static class Entry<K, V> {
}

@SuppressWarnings("unchecked")
static <K> Function<Entry<K, ?>, K> keyFunction() {
throw new UnsupportedOperationException();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public List<Class<?>> getListOfClass() { // Compliant Class is ignored
return null;
}

public Class<List<?>> getClassofList() { // Noncompliant
public Class<List<?>> getClassofList() { // Compliant, nested type is ignored
return null;
}

Expand All @@ -43,7 +43,7 @@ public List<? extends Class<String>> bar() { // Noncompliant {{Remove usage of g
}

public List<? // Noncompliant
extends List<?>> getSomething() { // Noncompliant
extends List<?>> getSomething() { // Compliant, skip nested wildcard return types
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void visitParameterizedType(ParameterizedTypeTree tree) {
} else if (!symbolType.is("java.lang.Class") && !symbolType.isUnknown()) {
typeArguments.forEach(this::reportIfWildcard);
}
super.visitParameterizedType(tree);
}

private void reportIfWildcard(Tree tree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ void test_non_compiling() {
.withCheck(new WildcardReturnParameterTypeCheck())
.verifyNoIssues();
}

@Test
void test_nested_types() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/WildCardReturnParameterNestedTypeSample.java"))
.withCheck(new WildcardReturnParameterTypeCheck())
.verifyNoIssues();
}
}