INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE 发现错误

INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE findbugs

我的掩护有误。

Suspicious integer expression (FB.INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE)

  1. defect: Bad comparison of nonnegative value with 0.

提出问题的代码

                  int [][] intarray = DB Call;
                  int noofRecord = intarray[0].length;
                    if(noofRecord < 0) {
                      //some stuf
                  }

如何解决上述错误。

你从 findbugs 得到这个提示是因为这个分析器检测到条件永远不会为真。

语言规范保证数组长度为非负数(JLS 16 10.7. Array Members):

The members of an array type are all of the following:

  • The public final field length, which contains the number of components of the array. length may be positive or zero.

[...]

因此,if 块中的代码永远无法执行,实际上是死代码。