posted 12 years ago
Aha! Change this line of code from
to
Why? The "|" operator always evaluates both of its operands: so even if current == null is true, it will still look at current.next == true, thus throwing the NPE for current.next. Whereas the "||" operator will only evaluate its RHS if its LHS is false. The latter is what you want in this case, and frankly in almost every case.
And don't ever respond to NPE by writing code which catches it. A NullPointerException always indicates a programming error which should be found and fixed, rather than ignored and worked around.
(Of course when I say "don't ever" and "always" there, there are always exceptions to such things. But if it's your code, that isn't one of the exceptions.)