使用以下代码,我得到NP_NULL_PARAM_DEREF: Method callpasses null for nonnull parameter:
public void calledAnywhereIDoNotCare() {
//[...]
//parameter could be null but shouldn't ever be by logic
method(parameter); //FindBugs says the problem is here
//[...]
}
public final ReturnType method(final ParameterType parameter) {
//this method do nothing but simply call anotherMethod()
return anotherMethod(parameter, false);
}
public final ReturnType anotherMethod(final ParameterType parameter, boolean boolParam) {
if (parameter == null) {
//just in case logic is wrong
throw new NullPointerException("I know it shouldn't be null by logic, but it is null!");
}
//do something very usefull
//[...]
}
所以,我的问题是:为什么我会得到这个 NP_NULL_PARAM_DEREF 以及哪些更改会更好?我得到这个是因为声明了参数final吗?还是因为没有捕捉到 NullPointerException?我不想抓住它,它应该在外面的某个地方被抓住。也许我应该在 calledAnywhereIDoNotCare() 中声明抛出 NullPointerException?
谢谢您的帮助。焦油