liaosusu 2011-12-25 13:40
浏览 224
已采纳

Findbug 代码检查 无限循环问题

/*
* copyString
* 拷贝一段字符串到新的字符串中
*/
public static String copyString(String src, int start, int len)
{
if(src == null)
{
return null;
}

    StringBuffer sb = new StringBuffer();

    for(int i = start; i < len; i++)
    {
        // 对src进行处理
    }

    return sb.toString();
}

findbugs插件检出高报警BUG。

Type Abbreviation Type Category

IL IL_INFINITE_LOOP:An apparent infinite
loop

This loop doesn't seem to have a way to terminate (other than by perhaps throwing an exception).

这个BUG该怎么改啊?多谢!

  • 写回答

1条回答 默认 最新

  • ll89308839 2011-12-26 09:01
    关注

    应该要判断下 start 和len
    if(start>=len) return null;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?