I’m seeing a false positive for S5860.
It wrongly identifies name
as being unreferenced even though it is referenced in the collect
.
I also see the same issue highlighted in Jetbrains (running Sonar Lint 10.7.0.78874). It seems to be related to its occurrence within the Streams API. If I uncomment the code block, the S5860 for name goes away.
Here’s a minimal reproducer. It seems
public class FalsePositiveS5860 {
private static final Pattern NAME_WITH_QUOTED_VALUE = Pattern.compile("^(?<name>[a-zA-Z_:][a-zA-Z0-9_:]*)=\"(?<value>.*)\"$");
public static void main(String[] argv) {
// var m = NAME_WITH_QUOTED_VALUE.matcher("foo=\"bar\"");
// m.matches();
// var name = m.group("name");
// var value = m.group("value");
// System.out.println("name " + name);
// System.out.println("value " + value);
System.out.println(Stream.of("foo=\"bar\"")
.map(NAME_WITH_QUOTED_VALUE::matcher)
.filter(Matcher::matches)
.collect(Collectors.toMap(nv -> nv.group("name"), nv -> nv.group("value"))));
}
}
IntelliJ IDEA 2023.2.7 (Ultimate Edition)
Build #IU-232.10319.17, built on June 6, 2024
You have a perpetual fallback license for this version.
Subscription is active until June 7, 2025.
Runtime version: 17.0.10+7-b1000.50 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 13.6.8
GC: G1 Young Generation, G1 Old Generation
Memory: 2512M
Cores: 16
Metal Rendering is ON
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
scala.erase.compiler.process.jdk.once=false
editor.minimap.enabled=true
Non-Bundled Plugins:
com.jetbrains.plugins.ini4idea (232.10319.17)
org.jetbrains.plugins.go-template (232.9921.89)
name.kropp.intellij.makefile (232.8660.88)
com.redhat.devtools.intellij.telemetry (1.1.0.52)
org.jetbrains.plugins.go (232.10203.2)
com.intellij.kubernetes (232.10203.2)
com.intellij.nativeDebug (232.10203.2)
com.jetbrains.nim (1.5.4-223)
com.intellij.guice (232.8660.142)
com.intellij.graalvm (232.9559.10)
CheckStyle-IDEA (5.92.0)
org.jetbrains.erlang (0.11.1205)
com.jetbrains.packagesearch.intellij-plugin (232.10319.17)
com.intellij.lang.jsgraphql (4.0.2)
org.intellij.scala (2023.2.30)
org.asciidoctor.intellij.asciidoc (0.40.9)
Pythonid (232.10319.17)
com.intellij.bigdatatools.core (232.10319.17)
com.intellij.bigdatatools.kafka (232.10319.17)
com.intellij.bigdatatools.binary.files (232.10072.27)
com.intellij.bigdatatools.rfs (232.10319.17)
com.intellij.bigdatatools.metastore.core (232.10319.17)
com.intellij.bigdatatools.flink (232.10072.27)
org.sonarlint.idea (10.7.0.78874)
com.intellij.bigdatatools.spark (232.10072.27)
com.intellij.bigdatatools.zeppelin (232.10072.27)
com.intellij.bigdatatools (232.10072.27)
Kotlin: 232-1.9.0-IJ10319.17