FindBugs

From EggeWiki

Jump to: navigation, search

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.

Object a[] = { "a", "b" };
System.out.println(a);

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

Object a[] = { "a", "b" };
System.out.println(Arrays.asList(a).toString());

which outputs [a, b].

Personal tools
Travelling Salesman

Get the app!