NullPointerException when initializing a BugAccumulator in the detector's constructor
Closed this issue · 6 comments
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);
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.
Oh, and thank you very much for raising the issue. Much appreciated.
Hi @paulur
This should be fixed now. Are you able to test the fix with a recent build? (removing the hack first of course)
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.
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.
Great. I will release a new version soon.