I have a few simple Java Streams in my code for these Streams SonarQube/Sonarlint shows as Noncompliant with the message:
Refactor the code so this stream pipeline is used.
Following are my Java Methods/Streams:
private static List<String> format(List<String> input) {
return input.stream().map(i -> DomainName + "/path/file-" + i).toList();
}
Another Noncompliant code sample is:
private static List<String> format1(List<String> input) {
return input.stream().map(String::toLowerCase).toList();
}
I believe these are simple Java Streams and they are working as expected for my requirement so not sure what's wrong with this. Can someone please explain what's wrong with this and how to fix the SonarQube issue?
Following is the Bug which is thrown by SonarQube:
Another Clarification
Which of the below is good to use as per Sonar and coding perspective?
I am currently creating a List something like this:
final List<String> myList = new ArrayList<>();
Update
So SonarCube tells me to declare it as var
so is it good to change it to
var myList = new ArrayList<>();
orfinal var myList = new ArrayList<>();