Description
NP: Possible null pointer dereference
There is a branch of statement that, if executed, guarantees that a null value will be dereferenced, which would generate a NullPointerException when the code is executed. Of course, the problem might be that the branch or statement is infeasible and that the null pointer exception can't ever be executed; deciding that is beyond the ability of FindBugs.
在多個分支中的某個變數,可能在使用時會是null,而造成nullpointer exception。
Solution
增加null檢查或Refactoring程式碼。
Example
Before:
IUser user = findUser(uid); if( user != null ){ removeUser(uid); } logger.debug("Remove user {}.", user.getKey());
After:
IUser user = findUser(uid); if( user != null ){ removeUser(uid); logger.debug("Remove user {}.", user.getKey()); }
有時被找出來只是findbugs無法確定這個是不是問題,但大都是存在一定的機率會發生。
留言
張貼留言