findbug检查问题指南.docxVIP

  • 3
  • 0
  • 约1.19万字
  • 约 13页
  • 2020-08-02 发布于上海
  • 举报
FindBugs常见问题指南 1? Comparison of String objects using == or != 例,override equals方法时容易犯错 Java代码 ? HYPERLINK "javascript:void() \o 收藏这段代码" if(this.topic?!=?key.getTopic()) ?? ????return?false; 2 Dead store to newStatusRecord ??? 定义局部变量后没有引用 3 Invocation of toString on values ?? 直接调用数组的toString方法 Java代码 ? HYPERLINK javascript:void() \o 收藏这段代码" public??Query?createQuery(String?hql,?Object?values[],Session?session){ ?? ??logger.debug(values); ?? ??logger.debug((new?StringBuilder()).append(hql=[).append(hql).append(]?).append(((Object)? ?? ?? }?? ?正确的例子,调用Arrays.toString()和Arrays.deepToString()方法。 Java代码 ? HYPERLINK javascript:void() \o "收藏这段代码  ?import?java.util.Arrays; ?? ?? class?A{ ?? ???? ?? } ?? class?B{ ?? ????@Override?? ????public?String?toString()?{ ?? ????????return?BBBBB"; ?? ????} ?? } ?? public?class?Test?{ ?? ????public?static?void?main(String[]?args)?{ ?? ?? ???????? ?? ????????Object?[]?a?=?{new?Integer(0),new?Boolean(true),true,new?A(),new?B()}; ?? ???????? ?? ????????Object[][]b?={{new?A(),new?B()},{new?A(),new?B()},{new?A(),new?B()}}; ?? ????????System.out.println(Arrays.deepToString(b)); ?? ???????? ?? ????} ?? }?? 4 ignores exceptional return value of java.io.() ?忽略了返回值,应当含有返回值 Java代码 ? HYPERLINK "javascript:void() \o 收藏这段代码 public?void?initFolder()?{ ?? ?(!exitDir.isDirectory())??{ ?? ????exitDir.mkdirs(); ?? ????("===Finishing?create?exit?trade?image?folder!===="); ?? } ?? ? This method returns a value that is not checked. The return value should be checked since it can indicate an unusual or unexpected function execution. For example, the () method returns false if the  not be successfully deleted (rather than throwing an Exception). If you don't check the result, you won't notice if the method invocation signals unexpected behavior by returning an atypical return value. 5 不使用new String()定义空的字符串 Java代码 ? HYPERLINK javascript:void()" \o 收藏这段代码 String?alarmCodeCond?=?new?String();?? ?应当? Java代码 ? HYPERLINK javascript:void() \o 收藏这段代码 String?al

文档评论(0)

1亿VIP精品文档

相关文档