tim-group / test-driven-detectors4findbugs

Test-Driven Detectors For FindBugs. Utility project to ease the development of custom plugin detectors for FindBugs.
Other
17 stars 17 forks source link

NullPointerException when initializing a BugAccumulator in the detector's constructor #13

Closed paulur closed 11 years ago

paulur commented 11 years ago

The Junit Code public class CipherVerifierTester { @Test public void raisesAnyBugAgainstClassWithLongName() throws Exception {

    // Must obtain a BugReporter instance from this method
    BugReporter bugReporter = DetectorAssert.bugReporterForTesting();

    // And pass the same BugReporter to your detector
    CipherVerifier detector = new CipherVerifier(bugReporter);

    // Next assert that your detector has raised a bug against a specific class
    DetectorAssert.assertBugReported(EncryptVerifierBenchmark.class, 
                                     detector, 
                                     bugReporter);
}

}

The Detector Code public class CipherVerifier implements Detector { BugReporter bugReporter; BugAccumulator bugAccumulator;
Method method; ClassContext classContext;

public CipherVerifier(BugReporter bugReporter) {
    this.bugReporter    = bugReporter;
    this.bugAccumulator = new BugAccumulator(bugReporter);
}

}

NullPointerException at the line of the detector code: this.bugAccumulator = new BugAccumulator(bugReporter);

2013-07-08_1143-junit

2013-07-08_1144-srccode

Grundlefleck commented 11 years ago

Thanks for raising. Definitely an bug to be fixed.

In the meantime, a functional (but nasty) workaround is to have this line of code run before your test executes, e.g. in the @Before or @BeforeClass of a JUnit test:

Class.forName("com.youdevise.fbplugins.tdd4fb.DetectorRunner$Singleton");

The reason is that FindBugs needs to set up static state to initialise a BugAccumulator (yuk). Prodding the classloader to initialise DetectorRunner$Singleton will trigger the initialisation.

This will be fixed to just work in the next release.

Grundlefleck commented 11 years ago

Oh, and thank you very much for raising the issue. Much appreciated.

Grundlefleck commented 11 years ago

Hi @paulur

This should be fixed now. Are you able to test the fix with a recent build? (removing the hack first of course)

paulur commented 11 years ago

Hey Graham,

Thanks for the update! I am traveling this week, but will try to see whether I could find sometime for reinstall the package. In any case, I'll get back to you by this Friday.

Thanks!

Paul

Sent from my iPhone

On Jul 14, 2013, at 10:07 AM, Graham Allan notifications@github.com wrote:

Hi @paulur

This should be fixed now. Are you able to test the fix with a recent build? (removing the hack first of course)

— Reply to this email directly or view it on GitHub.

paulur commented 11 years ago

Tested. Works well. Thanks!

Paul

Sent from my iPhone

On Jul 15, 2013, at 10:13 PM, Paul paulur@gmail.com wrote:

Hey Graham,

Thanks for the update! I am traveling this week, but will try to see whether I could find sometime for reinstall the package. In any case, I'll get back to you by this Friday.

Thanks!

Paul

Sent from my iPhone

On Jul 14, 2013, at 10:07 AM, Graham Allan notifications@github.com wrote:

Hi @paulur

This should be fixed now. Are you able to test the fix with a recent build? (removing the hack first of course)

— Reply to this email directly or view it on GitHub.

Grundlefleck commented 11 years ago

Great. I will release a new version soon.