FindBugs

From EggeWiki
Revision as of 23:16, 9 October 2007 by Egge (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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].