Matthieu Napoli
Matthieu Napoli

Reputation: 49703

Why do I get a "Possible null pointer dereference" warning?

Why do FindBugs raises me the following warning: Possible null pointer dereference.

current = myService.getCategoryParent(current);
if (current != null) { // The warning appears here

I don't understand how testing a variable against null could dereference it.

Upvotes: 1

Views: 4513

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1075567

I suspect the error/warning is actually on the line above the line you've indicated.

//                   here ------------v
current = myService.getCategoryParent(current);
if (current != null) {

Upvotes: 2

Related Questions