Open gianluca-nitti opened 3 years ago
I stumbled on this same issue when playing around with making a custom detector.
As best I can tell, you can have a "custom" category defined in your plugin descriptor, and that works fine:
<FindbugsPlugin>
<Detector class="..." reports="MUH_PATTERN" />
<BugCategory category="PROBLEMATIC" />
<BugPattern abbrev="FOO" type="MUH_PATTERN" category="PROBLEMATIC" />
</FindbugsPlugin>
The problem comes if your custom detector tries to refer to any of the "built-in" categories other than CORRECTNESS
.
Not sure why this is happening but it seems to be some interaction between the way the test harness AnalysisRunner
is constructing a UserPreferences
instance to pass to the engine.
preferences = UserPreferences.createDefaultUserPreferences();
preferences.getFilterSettings().clearAllCategories(); // <--- Eh?
preferences.enableAllDetectors(true);
engine.setUserPreferences(preferences);
@matthewlowry : if this is a bug, feel free to provide a patch for it.
I'm writing a SpotBugs plugin, starting from the maven archetype as suggested in the documentation.
I wrote a detector and some test classes for it. Also, I migrated the test code to JUnit5, using
SpotBugsExtension
class from thetest-harness-jupiter
artifact. Everything worked as expected until I tried to change the category of the detected bug, by changing the value of thecategory
attribute of theBugPattern
tag for the bug type reported by my detector infindbugs.xml
.The bugs in the "bad case" classes are in fact detected in my tests if the category is the default
CORRECTNESS
, but not, for example, if I set it toBAD_PRACTICE
orSTYLE
.Is it possible to instruct the
SpotBugsRunner
which the JUnit extension injects in my test methods to also detect bugs of these categories?