Invocation of toString on an array - FindBugs

Srinivasan picture Srinivasan · Jul 18, 2011 · Viewed 10.7k times · Source

I am getting the below Findbugs error for my code,

Invocation of toString on <<Package Path>>

 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. 

Code:

logger.info("Adding information"+ Employee.getName()+ " "+
            employeeForm.getQuestionAndAnswers());

Please let me know what is the error.

Answer

MeBigFatGuy picture MeBigFatGuy · Jul 18, 2011

As it says, doing

myArray.toString()

will generate something useless like java.lang.int[]@45345262

you'd want to use

Arrays.toString(myArray);