FindBugs: Difference between revisions

From EggeWiki
m (New page: [http://findbugs.sourceforge.net/ FindBugs] is an open source project which identifies potential problems with your code by doing byte code analysis. Here are some common problems, and ea...)
 
mNo edit summary
 
Line 1: Line 1:
[http://findbugs.sourceforge.net/ FindBugs] is an open source project which identifies potential problems with your code by doing byte code analysis.  Here are some common problems, and easy fixes:
[http://findbugs.sourceforge.net/ FindBugs] is an open source project which identifies potential problems with your code by doing byte code analysis.  Here are some common problems, and easy fixes:


'''Invocation of toString on an array'''
=== Invocation of toString on an array ===


The code invokes toString on an array, which will generate a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12.  
The code invokes toString on an array, which will generate a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12.  

Latest revision as of 23:17, 9 October 2007

FindBugs is an open source project which identifies potential problems with your code by doing byte code analysis. Here are some common problems, and easy fixes:

Invocation of toString on an array

The code invokes toString on an array, which will generate a fairly useless result such as [C@16f0472. Consider using Arrays.toString to convert the array into a readable String that gives the contents of the array. See Programming Puzzlers, chapter 3, puzzle 12.

<geshi lang="java5"> Object a[] = { "a", "b" }; System.out.println(a); </geshi>

The result is [Ljava.lang.Object;@12152e6. A better way to do this is:

<geshi lang="java5"> Object a[] = { "a", "b" }; System.out.println(Arrays.asList(a).toString()); </geshi>

which outputs [a, b].