Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Why is that? Does FindBugs not see that this is a junit test? (and therefore setUp() is called before executing each test)</p> </blockquote> <p>Basically, yes. It is pretty obvious that FindBugs doesn't have special knowledge of JUnit test cases and how they work. (I'm a little surprised that you are even running FindBugs over your unit tests ...)</p> <blockquote> <p>One workaround is to add this class annotation ... Any better idea?</p> </blockquote> <p>It is simpler to explicitly initialize the field to <code>null</code>. That will should satisfy FindBugs.</p> <hr> <blockquote> <p>Yes, I hesitated to add NonNull annotations in the tests; but the tests themselves can contain bugs, so why not? Why not running FindBugs over the unit tests? </p> </blockquote> <p>Because of problems like this! </p> <p>Unit tests are qualitatively different to ordinary code. For instance, if the <code>foo</code> field was accidentally left <code>null</code>, then the worst that can happen is that the unit test will crash, you will spot the bug and fix it. It is not going to directly break production code, and will only have any impact at all if you are in the habit of ignoring failed unit tests.</p> <blockquote> <p>I cannot initialize foo to null, since it is defined as NonNull (by the DefaultAnnotation)</p> </blockquote> <p>Well according to TimK's answer, that means that <code>foo</code> MUST be non-null after the constructor has finished executing. Given that you have specified that invariant for your entire codebase (including the testcases) you must either stick to it, or add an exception.</p> <p>One kludge might be to create a dummy <code>Foo</code> instance, and use that to initialize <code>foo</code>. But it is more straightforward to just to add the SuppressWarnings ...</p> <hr> <p>Frankly, you need to think a bit more deeply about what you are trying to achieve with FindBugs. Running it on your unit tests seems to be creating more problems than it solves.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload