Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tool to verify null check (FindBugs, CheckStyle ..)

 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I often forget to check if an object is null before using it.
Do you know any tool (like FindBugs, CheckStyle ...) that can detect whether an object is checked before it is used and give alarm to programmer?

Thank you very much.
 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use FindBugs. It shows me all the places where exception can come in future.

example. suppose i have a method



On this if i run findbug, it warns me at line if(cmpStr.equals("yes").
It says dont do cmpStr.equals("yes") do "yes".equals(cmpStr)
 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siddhesh Deodhar wrote:I use FindBugs. It shows me all the places where exception can come in future.

example. suppose i have a method



On this if i run findbug, it warns me at line if(cmpStr.equals("yes").
It says dont do cmpStr.equals("yes") do "yes".equals(cmpStr)


Thank you very much
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too use FindBugs, its quite useful.
 
Swerrgy Smith
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just checked with FindBugs. It can only find simple null check. However, if we wrote something like following code:


instead of



In this case, FindBugs will not detect what we have forgotten.
Which tool can be used for this purpose?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic