为什么我会收到“可能的空指针解除引用”警告?
为什么FindBugs的提高了我以下警告:Possible null pointer dereference。为什么我会收到“可能的空指针解除引用”警告?
current = myService.getCategoryParent(current);
if (current != null) { // The warning appears here
我不明白如何测试一个变量对null可以解引用它。
我怀疑的错误/警告实际上是在线之上你的指示线。
// here ------------v
current = myService.getCategoryParent(current);
if (current != null) {
声纳报告在第二行的警告,但我加了上面只是要确定,因为我也有一个疑问......如果是这样的话,那会是什么预警线是关于? – 2012-04-25 09:01:16
@Matthieu:大概它担心'getCategoryParent'将取消引用传入的参数? 'getCategoryParent'是否有'!null'检查? – 2012-04-25 09:02:47
是的,有一个'!= null'检查。然而'getCategoryParent'可以返回'null',可能是这样吗? – 2012-04-25 09:05:13
什么是当前的类型? – 2012-04-25 08:58:37
@MichaelBorgwardt这是一个自定义的'Category'类 – 2012-04-25 09:00:14
是目前在所有后使用/超出这个if语句? – BeRecursive 2012-04-25 09:00:57