2012-04-25 113 views
1

爲什麼FindBugs的提高了我以下警告:Possible null pointer dereference爲什麼我會收到「可能的空指針解除引用」警告?

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

我不明白如何測試一個變量對null可以解引用它。

+3

什麼是當前的類型? – 2012-04-25 08:58:37

+0

@MichaelBorgwardt這是一個自定義的'Category'類 – 2012-04-25 09:00:14

+0

是目前在所有後使用/超出這個if語句? – BeRecursive 2012-04-25 09:00:57

回答

2

我懷疑的錯誤/警告實際上是在線之上你的指示線

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

聲納報告在第二行的警告,但我加了上面只是要確定,因爲我也有一個疑問......如果是這樣的話,那會是什麼預警線是關於? – 2012-04-25 09:01:16

+0

@Matthieu:大概它擔心'getCategoryParent'將取消引用傳入的參數? 'getCategoryParent'是否有'!null'檢查? – 2012-04-25 09:02:47

+0

是的,有一個'!= null'檢查。然而'getCategoryParent'可以返回'null',可能是這樣嗎? – 2012-04-25 09:05:13

相關問題