java - How to fix the Findbugs issue "Null value is guaranteed to be dereferenced" NP_GUARANTEED_DEREF -


Hello, I've got some code that has been reported by Findbugs as a NP_GUARANTEED_DEREF problem. Now seeing my code I do not understand what is wrong with it, nobody can tell what the problem is.

  Public Zero Test () {string var = ""; Int index = 2; If (index == -1) {var = String.class.getName (); If (var.length () == 0) {var = null; }} And {var = Integer.class.getName (); If (var.length () == 0) {var = null; }} If (var == null) {// FINBUGS report on this line NP_GUARANTEED_DEREF / * * is a statement or branch that guarantees that the value is * tap on this point, and that value is guaranteed * Dereferenced ( Excluding routes that include runtime exceptions) * / New throwpoint exuption ("NULL"); }}   

Now findbugs in the error drilling it var = null; Highlights two assignments for the reason of the bug, but I do not quite understand why. It's not that I'm actually doing anything with the var object, I'm only doing a null check. The example is taken from the actual output code, but has stripped anything that did not need to reproduce the error. I am wondering if this is a false positive or not and if not, what would be the right decision.

Here is a link to findbugs bug extension:

[UPDATE] After receiving some feedback on this issue, I have now logged into it Findbugs on Sourceforge Bugtracker in a false positive < / P>

There will be conversation about the problem.

I see I can confirm the same FB behavior on my computer, really sounds weird What's strange is, if you change with the new NullPointer Exposure , then the new runtime exposure will be lost the bug marker will disappear.

Now I think that I have understood what they mean by means. The word wording is not correct, but they are warning you against NPE. I think they clearly think of throwing bad practice to NPE.

Comments