[FB-Discuss] bugfix for findbugs.de.comment not working

Dave Brosius dbrosius at mebigfatguy.com
Fri Apr 4 11:56:01 EDT 2008


Are you compiling your code with -g?


-----Original Message-----
From: Peter Fokkinga <p.r.fokkinga at rug.nl>
Sent: Friday, April 4, 2008 11:03am
To: findbugs-discuss at mcfeely.cs.umd.edu
Subject: [FB-Discuss] bugfix for findbugs.de.comment not working

Hello,

According to the manual the following code should not result in
a warning when the findbugs.de.comment property is set to true.

try {
   String id = gm.getCourseMembershipId().toExternalString();
   System.out.println("CourseMembership " + id + " not found (ignored)");
} catch (Exception e) {
   // this space intentionally left blank
}

FindBugs 1.3.3 however does report this code as a DroppedException. In
fact, the number of warnings for my code went up from 13 to 17 instead
of going down when specifying findbugs.de.comment=true...

After some poking in the source I noticed that catchBlockHasComment()
in DroppedException called getLineOffset() on a SourceFile that
had not loaded the filedata yet (SourceFile has lazy initialization).
Because of that getLineOffset() always returned -1 causing
catchBlockHasComment() to always return false.

The attached patch fixes this by always calling loadFileData() from
getLineOffset(). I choose to catch the IOException so the rest of
the codebase can be left untouched.

The patch is against 1.3.3 but SourceFile has not been changed since
so it should cleanly apply to subversion HEAD as well.


Kind regards, Peter Fokkinga
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss at mcfeely.cs.umd.edu
http://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss






More information about the Findbugs-discuss mailing list