findBugs例子1

 

 

 

String[] idArray = idList.split(",");
if (result.isSuccess() == false) {
				log.error("发送站内信:mobileList=" + idArray + ",content=" + content);
			}

 find bug会报错:

Bug: Invocation of toString on idArray
Pattern 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.

 

大概意思是:

数组打印的时候:通过一个char值给println打印一个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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值