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

This file was deleted.

This file was deleted.

17 changes: 0 additions & 17 deletions its/ruling/src/test/resources/expected/guava/java-S2387.json

This file was deleted.

6 changes: 6 additions & 0 deletions its/ruling/src/test/resources/expected/guava/java-S3551.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"guava:src/com/google/common/hash/HashingInputStream.java": [
88,
95
]
}
8 changes: 0 additions & 8 deletions its/ruling/src/test/resources/expected/guava/java-S5738.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
{
"guava:src/com/google/common/base/Throwables.java": [
337,
367,
370
],
"guava:src/com/google/common/cache/Striped64.java": [
321
],
"guava:src/com/google/common/io/FileBackedOutputStream.java": [
103
],
"guava:src/com/google/common/primitives/UnsignedBytes.java": [
364
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,22 @@ void compliant() {
List<String> list6 = Stream.of("B", "C", "D")
.collect(Collectors.toList()); // Compliant, list6 needs to be mutable

list6.addFirst("A");
list6.add(0, "A");

List<String> list7 = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, list7 needs to be mutable

list7.addLast("D");
list7.add("D");

List<String> list8 = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, list8 needs to be mutable

list8.removeFirst();
list8.remove(0);

List<String> list9 = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, list9 needs to be mutable

Comment thread
gitar-bot[bot] marked this conversation as resolved.
Resolved
list9.removeLast();
list9.remove("C");
}

void addX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,22 @@ void compliant() {
List<String> list6 = Stream.of("B", "C", "D")
.collect(Collectors.toList()); // Compliant, list6 needs to be mutable

list6.addFirst("A");
list6.add(0, "A");

List<String> list7 = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, list7 needs to be mutable

list7.addLast("D");
list7.add("D");

List<String> list8 = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, list8 needs to be mutable

list8.removeFirst();
list8.remove(0);

List<String> list9 = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, list9 needs to be mutable

list9.removeLast();
list9.remove("C");
}

void addX() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package checks;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CollectorsToListCheckSequencedSample {

void noncompliant() {
List<String> list = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Noncompliant {{Replace this usage of 'Stream.collect(Collectors.toList())' with 'Stream.toList()' and ensure that the list is unmodified.}}
// ^^^^^^^^^^^^^^^^^^^

list.getFirst();
}

void compliant() {
List<String> addFirst = Stream.of("B", "C", "D")
.collect(Collectors.toList()); // Compliant, addFirst needs to be mutable

addFirst.addFirst("A");

List<String> addLast = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, addLast needs to be mutable

addLast.addLast("D");

List<String> removeFirst = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, removeFirst needs to be mutable

removeFirst.removeFirst();

List<String> removeLast = Stream.of("A", "B", "C")
.collect(Collectors.toList()); // Compliant, removeLast needs to be mutable

removeLast.removeLast();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ public class StringIsBlankCheckSample_java10 {
public boolean sample(String s) {
boolean b;

// `String.isBlank()` does not exist before Java 11, so these stay emptiness checks on the trimmed string

b = s.strip().length() == 0; // Noncompliant {{Use "isEmpty()" to check whether a "String" is empty or not.}} [[quickfixes=qf1]]
// fix@qf1 {{Replace with "isEmpty()"}}
// edit@qf1 [[sc=19;ec=32]]{{isEmpty()}}

b = s.strip().length() > 0; // Noncompliant {{Use "isEmpty()" to check whether a "String" is empty or not.}} [[quickfixes=qf2]]
// fix@qf2 {{Replace with "isEmpty()"}}
// edit@qf2 [[sc=9;ec=9]]{{!}}
// edit@qf2 [[sc=19;ec=31]]{{isEmpty()}}
// `String.isBlank()` does not exist before Java 11, so trimmed strings are plain emptiness checks

b = s.trim().length() == 0; // Noncompliant {{Use "isEmpty()" to check whether a "String" is empty or not.}} [[quickfixes=qf3]]
// fix@qf3 {{Replace with "isEmpty()"}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ void test() {
.verifyIssues();
}

@Test
void test_sequenced_collection_mutators() {
CheckVerifier.newVerifier()
.onFile(mainCodeSourcesPath("checks/CollectorsToListCheckSequencedSample.java"))
.withCheck(new CollectorsToListCheck())
.withJavaVersion(21)
.verifyIssues();
}

@Test
void test_no_issues_for_older_versions() {
createCheckVerifier()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ void test() {
.withJavaVersion(11)
.verifyNoIssues();
} else {
// No issue raised starting JDK 11 as the related APIs were removed from JDK and cannot be resolved
// No issue raised by default starting JDK 11 as the related APIs were removed from JDK and cannot be resolved,
// unless the analyzed Java version is 10, for which the APIs of that release are visible
CheckVerifier.newVerifier()
.onFile(nonCompilingTestSourcesPath("checks/RunFinalizersCheckNoIssue.java"))
.withCheck(new RunFinalizersCheck())
Expand All @@ -58,10 +59,10 @@ void test() {
.withJavaVersion(javaVersion)
.verifyNoIssues();
CheckVerifier.newVerifier()
.onFile(nonCompilingTestSourcesPath("checks/RunFinalizersCheckNoIssue.java"))
.onFile(nonCompilingTestSourcesPath("checks/RunFinalizersCheckSample.java"))
.withCheck(new RunFinalizersCheck())
.withJavaVersion(10)
.verifyNoIssues();
.verifyIssues();
}
}

Expand Down
2 changes: 1 addition & 1 deletion java-frontend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jdt-package</artifactId>
<version>1.9.0.1840</version>
<version>1.9.0.12280</version>
</dependency>

<dependency>
Expand Down
Loading
Loading