IG: Expression may produce null pointer

In my test code, I often use the following convention:

assertTrue("Something didnt' work",foo.doSomething());

to avoid null pointer exceptions, or complex checking in the assert true.

Unfortunately IG tells me that foo might be null, when it obviously (to me anyway) can't.

2 questions

1) Could IG tell? (I mean if expr could be null, was expr used in previous assertNotNull statement?)

2) If not, perhaps I'm should add the extra syntax to check for null by hand? (seems extra work for no advantage).


Comment actions Permalink

The "May Be Null" inspection isn't part of IG, it's part of the built-in IDEA exceptions. You should post a tracker item asking to have the inspection be made aware of assertNotNull(). It's reasonable, considering the depth of IDEA's JUnit integration.

--Dave Griffith


Please sign in to leave a comment.