findBugs例1
String[] idArray = idList.split(",");
if (result.isSuccess() == false) {
log.error(" :mobileList=" + idArray + ",content=" + content);
}
findバグはエラーを報告します.
Bug: Invocation of toString on idArrayPattern id: DMI_INVOKING_TOSTRING_ON_ARRAY, type: USELESS_STRING, category: CORRECTNESS
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.
意味は次のとおりです.
配列印刷時:printlnに数値コードではなくchar値でUnicode文字を印刷します.
解決策
と書く
方法1
log.error(「送信局内手紙:mobileList=」+String.ValueOf(idArray)+「,content=」+content);
方法2
System.out.println(idArray);
まだ分かりません:log.error(idArray)
To summarize, char arrays are not strings. To convert a char array to a string, invoke String.valueOf(char[]). Some library methods do provide stringlike support for char arrays, typically having one overloading for Object and another for char[]; only the latter has the desired behavior.
The lesson for language designers is that the char[] type should probably have overridden toString to return the characters contained in the array. More generally, the array types should probably have overridden toString to return a string representation of the contents of the array