Why do I get a “Possible null pointer dereference” warning?

大城市里の小女人 提交于 2019-12-11 09:19:09

问题


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.


回答1:


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) {


来源:https://stackoverflow.com/questions/10312399/why-do-i-get-a-possible-null-pointer-dereference-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!