spotbugs / spotbugs

SpotBugs is FindBugs' successor. A tool for static analysis to look for bugs in Java code.
https://spotbugs.github.io/
GNU Lesser General Public License v2.1
3.46k stars 585 forks source link

ignore Scala code #1029

Open h-ngo opened 4 years ago

h-ngo commented 4 years ago

How can we config Spotbugs to not scanning Scala codes?

We encountered false-positive violations in Scala codes due to findbugs in our java profile being applied to Scala.

Line of code violated: val spokenLanguage = abcSpokenLanguage.map { language => // <-- violated

Rule: "Nullcheck of Language at line xxx of value previously dereferenced in ...."

Spotbugs version: 3.11.1 SonarJava: 5.14

welcome[bot] commented 4 years ago

Thanks for opening your first issue here! :smiley: Please check our contributing guideline. Especially when you report a problem, make sure you share a Minimal, Complete, and Verifiable example to reproduce it in this issue.

ThrawnCA commented 4 years ago

Since SpotBugs acts on bytecode, I'm not sure that there's any way for it to reliably distinguish Java code from Scala.

If the Scala code is in specific packages, you could exclude those packages from all scanning, or from selected rules.

tokuhirom commented 4 years ago

@ThrawnCA I guess, spotbugs can detect the source language type by source file name. ref. https://github.com/tokuhirom/classfileops-sample