I recently started using the findbugs static analysis tool in the java assembly I was doing. The first report returned with many warnings of high priority. Being an obsessive person, I was ready to knock everything out. However, I have to miss something. I get most warnings when comparing things. For example, the following code:
public void setSpacesPerLevel(int value) { if( value >= 0) { spacesPerLevel = value; } else { spacesPerLevel = 0; } }
throws a high priority warning in an if statement that reads.
File: Indenter.java, Line: 60, Type: BIT_AND_ZZ, Priority: High, Category: CORRECTNESS Check to see if ((...) & 0) == 0 in sample.Indenter.setSpacesPerLevel (integer)
I am comparing int with int, it seems like a normal thing. I get quite a lot of such errors with similar simple comparisons.
I have many other high priority warnings that appear to be simple blocks of code. Am I missing something? I understand that static analysis can produce false positives, but the errors that I see seem too trivial for the case to be false.
I have scratches too.
for(int spaces = 0;spaces < spacesPerLevel;spaces++) { result = result.concat(" "); }
What gives a warning about downstream errors:
File: Indenter.java, Line: 160, Type: IL_INFINITE_LOOP, Priority: High, Category: CORRECTNESS There is an apparent infinite loop in sample.Indenter.indent() This loop doesn't seem to have a way to terminate (other than by perhaps throwing an exception).
Any ideas?
So basically I have several files and 50-60 warnings with high priority similar to the above. I am using findbugs 1.3.9 and calling it from the findbugs ant task
UPDATE: I have this assembly performed by the hudson server, and the code has been integrated by Clover to cover the code. When I turned it off, all of my high priority warnings disappeared. Now that makes sense. Thanks for the feedback.
java static-analysis findbugs
Rob goodwin
source share