Java puzzlers and findbugs

Programmers need all the help they can get. It can be a thankless task sometimes and language designers with the best intentions cause misleading behavior to occur even in the simplest of code. The authors of Java Puzzlers, have mined the Java specifications misleading problems that cause issues in production code. It makes interesting reading, it can also points to scary traps that could trip up the hapless programmer. They do however recommend a tool called findbugs that will literally find bugs in your software. Java puzzlers forms a good companion to the tool, explaining the reasons behind why certain practices are worse than others. The impressive thing about the tool is that it has found old bugs in well maintained code like the jdk. For example null-pointer issues that have existed for ten years.

I use this software from ant. In your project you can run findbugs much like the compiler: The example below is slightly different from the one given in the manual: it uses the tasks.properties file to define the tasks available.

<property name="findbugs.home" value="${test.lib}/findbugs-1.3.4" />
<path id="findbugs.lib">
   <fileset dir="${findbugs.home}/lib">
	<include name="*.jar"/>
   </fileset>		
</path>
 
<taskdef classpathref="findbugs.lib" resource="edu/umd/cs/findbugs/anttask/tasks.properties"/>
 
<target name="findbugs" depends="compile.src">
 <findbugs home="${findbugs.home}"
		     output="html"
		     outputFile="${build}/test-reports/findbugs-report.html" >
   <auxClasspath refid="main.classpath" />
   <sourcePath path="${src}" />
   <class location="${src.classes}" />
</findbugs> 
</target>

Another interesting feature of this tool is that a bug history can be produced from a number of bug reports. This can give meaningful metrics on how buggy a system is over a number of releases.

BlogTag: 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.