help with 'null pointer dereference'

38 views
Skip to first unread message

Dave

unread,
Jul 30, 2008, 1:01:03 PM7/30/08
to FindBugs
Hello

I'm new to this tool, so I may misunderstand what it's telling me.
FindBugs first flagged the condition on line 2, which I fixed with
if (allDataIds != null && allDataIds.size() != 0) {

But now FindBugs insists the NP dereference error is on line 3. I've
tried declaring the local variable and it still remembers
'allDataIds'. See Ex 2. Appreciate any help! -Dave

Ex1.
1 pubic void foo(List allDataIds) {
2 if (allDataIds != null || allDataIds.size()== 0) {
3 a = process1(this, allDataIds);
4 process2(a);
5 }
6 }

Ex2.
1 pubic void foo(List allDataIds) {
2 List x = new ArrayList();
2 if (x != null && x.size() != 0) {
3 a = process1(this, x);
4 process2(a);
5 }
6 }

StephenGregory

unread,
Jul 30, 2008, 1:34:24 PM7/30/08
to FindBugs
I think something may have been lost in the sanitization, but my guess
is that is complaining that the value of identifier 'a' might be null.

StephenGregory

unread,
Jul 30, 2008, 1:37:14 PM7/30/08
to FindBugs
Also have you tried doing a clean build?

Dave

unread,
Jul 30, 2008, 2:08:36 PM7/30/08
to FindBugs
Doh! :)

thanks! after the clean build, the NP Dereference bug is gone.

-Dave
Reply all
Reply to author
Forward
0 new messages