Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Findbug continues to report the same bugs

 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble fixing the bugs that are found.

For example, the following bug was identified



Produces the bug "Pattern: Call to static DateFormat ..."

Replaced the code with



But, I continue to get the message: "Pattern: Call to static DateFormat ..."


Also, I had a class that override equal. I got the message: "Bug: support.tree.NeuralNetConfiguration defines equals and uses Object.hashCode()".
The bug message appeared on the declartion of the equal member.
So, I wrote the hashCode for the class, and now the message appears on the first line of the hashCode member, which has the same line number as the previous location of member equal.

It looks like find bug is reporting previous errors. I'm in Eclipse, and have done project clean/rebuild, and changed the settings on findbug to work harder. But, continue to get message that appear to be from the original source code, and not being updated with the modified source code.

Any suggestions / recommendations?

John
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15441
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why FindBugs exactly gives you that first error message. But on the FindBugs website you can look it up in the list of bug descriptions, where you'll find more info on what the message means exactly and how you could solve it.

For the second point: Whenever you override equals(), you should override hashCode() as well. These two methods are used together by hash-based collections such as HashMap and HashSet. If they are not implemented according to the rules described in the API documentation for Object.hashCode, then your class will not work properly when used as a HashMap key or value in a HashSet.

See also item 9 in Effective Java.
 
John Vorwald
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comments.

Seems that the problem was that I had turned off automatic build in Eclipse. So, after modifying the code, findbugs was still looking at the build from the original code. Alternatively, I can leave automatic build off, and then have to do a manual build before running findbugs.

Cheers,
John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic