Skip to content
This repository has been archived by the owner on Oct 22, 2023. It is now read-only.

BugPattern categories and plugin testing #111

Open
gianluca-nitti opened this issue Jun 12, 2021 · 2 comments
Open

BugPattern categories and plugin testing #111

gianluca-nitti opened this issue Jun 12, 2021 · 2 comments

Comments

@gianluca-nitti
Copy link

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 the test-harness-jupiter artifact. Everything worked as expected until I tried to change the category of the detected bug, by changing the value of the category attribute of the BugPattern tag for the bug type reported by my detector in findbugs.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 to BAD_PRACTICE or STYLE.

Is it possible to instruct the SpotBugsRunner which the JUnit extension injects in my test methods to also detect bugs of these categories?

@matthewlowry
Copy link

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);

@iloveeclipse
Copy link
Member

@matthewlowry : if this is a bug, feel free to provide a patch for it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants