From 422ab0d24c06aff340062439aae2189b0d082db1 Mon Sep 17 00:00:00 2001 From: "pixeebot-test[bot]" <123999551+pixeebot-test[bot]@users.noreply.github.com> Date: Sun, 21 Jul 2024 02:00:32 +0000 Subject: [PATCH] (Sonar) Fixed finding: "`Stream.toList()` should be used instead of `collectors`" --- .../java/io/codemodder/codemods/VerbTamperingCodemod.java | 4 ++-- .../codemodder-base/src/main/java/io/codemodder/CLI.java | 2 +- .../src/main/java/io/codemodder/CodemodReporterStrategy.java | 2 +- .../src/main/java/io/codemodder/DefaultCodemodExecutor.java | 4 ++-- .../main/java/io/codemodder/DefaultXPathStreamProcessor.java | 4 ++-- .../src/main/java/io/codemodder/ParameterModule.java | 2 +- .../src/main/java/io/codemodder/RawFileChanger.java | 2 +- .../main/java/io/codemodder/javaparser/JavaParserChanger.java | 2 +- .../io/codemodder/plugins/maven/operator/POMOperator.java | 2 +- .../plugins/maven/operator/ProjectModelFactory.java | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core-codemods/src/main/java/io/codemodder/codemods/VerbTamperingCodemod.java b/core-codemods/src/main/java/io/codemodder/codemods/VerbTamperingCodemod.java index 54b69604c..ab07d1de6 100644 --- a/core-codemods/src/main/java/io/codemodder/codemods/VerbTamperingCodemod.java +++ b/core-codemods/src/main/java/io/codemodder/codemods/VerbTamperingCodemod.java @@ -63,7 +63,7 @@ private List processWebXml(final CodemodInvocationContext context // add the weaves to the context List changes = - linesAffected.stream().map(CodemodChange::from).collect(Collectors.toList()); + linesAffected.stream().map(CodemodChange::from).toList(); // overwrite the previous web.xml with the new one Files.copy(xmlChange.transformedXml(), file, StandardCopyOption.REPLACE_EXISTING); @@ -109,6 +109,6 @@ public String getIndividualChangeDescription(final Path filePath, final CodemodC public List getReferences() { return reporter.getReferences().stream() .map(u -> new CodeTFReference(u, u)) - .collect(Collectors.toList()); + .toList(); } } diff --git a/framework/codemodder-base/src/main/java/io/codemodder/CLI.java b/framework/codemodder-base/src/main/java/io/codemodder/CLI.java index 03f023e44..f0fde624c 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/CLI.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/CLI.java @@ -488,7 +488,7 @@ public Integer call() throws IOException { String.join(" ", args), sarifs == null ? List.of() - : sarifs.stream().map(Path::of).collect(Collectors.toList()), + : sarifs.stream().map(Path::of).toList(), results, elapsed); ObjectMapper mapper = new ObjectMapper(); diff --git a/framework/codemodder-base/src/main/java/io/codemodder/CodemodReporterStrategy.java b/framework/codemodder-base/src/main/java/io/codemodder/CodemodReporterStrategy.java index bfbedbd05..69693b80c 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/CodemodReporterStrategy.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/CodemodReporterStrategy.java @@ -118,7 +118,7 @@ private static CodemodReporterStrategy getCodemodReporterStrategy( List references = StreamSupport.stream(referencesNode.spliterator(), false) .map(JsonNode::asText) - .collect(Collectors.toList()); + .toList(); return new CodemodReporterStrategy() { @Override diff --git a/framework/codemodder-base/src/main/java/io/codemodder/DefaultCodemodExecutor.java b/framework/codemodder-base/src/main/java/io/codemodder/DefaultCodemodExecutor.java index 53f8bbc3e..9f2cea134 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/DefaultCodemodExecutor.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/DefaultCodemodExecutor.java @@ -234,7 +234,7 @@ private FilesUpdateResult updateFiles( .map(CodemodChange::getDependenciesNeeded) .flatMap(Collection::stream) .distinct() - .collect(Collectors.toList()); + .toList(); List pkgActions; List dependencyChangesetEntries = Collections.emptyList(); @@ -253,7 +253,7 @@ private FilesUpdateResult updateFiles( .map( change -> translateCodemodChangetoCodeTFChange(codeChanger, filePath, change, pkgActions)) - .collect(Collectors.toList()); + .toList(); // make sure we add the file's entry first, then the dependency entries, so the causality // is clear diff --git a/framework/codemodder-base/src/main/java/io/codemodder/DefaultXPathStreamProcessor.java b/framework/codemodder-base/src/main/java/io/codemodder/DefaultXPathStreamProcessor.java index ce9c6beeb..6fc938056 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/DefaultXPathStreamProcessor.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/DefaultXPathStreamProcessor.java @@ -58,7 +58,7 @@ public Optional process( DocumentHelper.selectNodes(xpathExpression, doc).stream() .map(node -> (LocationAwareElement) node) .map(element -> new Position(element.getLine(), element.getColumn())) - .collect(Collectors.toUnmodifiableList()); + .toList(); if (httpMethodPositions.isEmpty()) { return Optional.empty(); @@ -97,7 +97,7 @@ public Optional process( // remove the empty leftover lines affected by our changes if there are any Set linesAffected = httpMethodPositions.stream().map(pos -> pos.line()).collect(Collectors.toUnmodifiableSet()); - List lines = transformedXml.lines().collect(Collectors.toUnmodifiableList()); + List lines = transformedXml.lines().toList(); List updatedLines = new ArrayList<>(lines.size() - linesAffected.size()); for (int i = 1; i <= lines.size(); i++) { String actualLine = lines.get(i - 1); diff --git a/framework/codemodder-base/src/main/java/io/codemodder/ParameterModule.java b/framework/codemodder-base/src/main/java/io/codemodder/ParameterModule.java index f4a8d60e8..9833466c4 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/ParameterModule.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/ParameterModule.java @@ -33,7 +33,7 @@ protected void configure() { this.injectableParameters.stream() .filter(param -> param.isAnnotationPresent(CodemodParameter.class)) .filter(param -> param.getType().equals(Parameter.class)) - .collect(Collectors.toUnmodifiableList()); + .toList(); for (java.lang.reflect.Parameter param : codemodParameters) { CodemodParameter codemodParameter = param.getAnnotation(CodemodParameter.class); diff --git a/framework/codemodder-base/src/main/java/io/codemodder/RawFileChanger.java b/framework/codemodder-base/src/main/java/io/codemodder/RawFileChanger.java index b88606d50..791827483 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/RawFileChanger.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/RawFileChanger.java @@ -47,6 +47,6 @@ public String getIndividualChangeDescription(final Path filePath, final CodemodC public List getReferences() { return reporter.getReferences().stream() .map(u -> new CodeTFReference(u, u)) - .collect(Collectors.toList()); + .toList(); } } diff --git a/framework/codemodder-base/src/main/java/io/codemodder/javaparser/JavaParserChanger.java b/framework/codemodder-base/src/main/java/io/codemodder/javaparser/JavaParserChanger.java index b1929a6dd..ec5aa8413 100644 --- a/framework/codemodder-base/src/main/java/io/codemodder/javaparser/JavaParserChanger.java +++ b/framework/codemodder-base/src/main/java/io/codemodder/javaparser/JavaParserChanger.java @@ -43,6 +43,6 @@ public String getIndividualChangeDescription(final Path filePath, final CodemodC public List getReferences() { return reporter.getReferences().stream() .map(u -> new CodeTFReference(u, u)) - .collect(Collectors.toList()); + .toList(); } } diff --git a/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/POMOperator.java b/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/POMOperator.java index 8d07cb2f4..285905333 100644 --- a/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/POMOperator.java +++ b/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/POMOperator.java @@ -183,7 +183,7 @@ static Optional queryVersions(ProjectModel projectModel) if (queryVersionResult.size() == 1) { List queryVersionResultList = queryVersionResult != null && !queryVersionResult.isEmpty() - ? queryVersionResult.stream().collect(Collectors.toList()) + ? queryVersionResult.stream().toList() : Collections.emptyList(); Version mappedVersion = mapVersion(queryVersionResultList.get(0).getValue()); diff --git a/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/ProjectModelFactory.java b/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/ProjectModelFactory.java index 4761abfdc..85484a7c6 100644 --- a/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/ProjectModelFactory.java +++ b/plugins/codemodder-plugin-maven/src/main/java/io/codemodder/plugins/maven/operator/ProjectModelFactory.java @@ -48,7 +48,7 @@ public ProjectModelFactory withPomFile(POMDocument pomFile) { public ProjectModelFactory withParentPomFiles(Collection parentPomFiles) { this.parentPomFiles = new ArrayList<>( - parentPomFiles.stream().filter(Objects::nonNull).collect(Collectors.toList())); + parentPomFiles.stream().filter(Objects::nonNull).toList()); return this; }