FindBugs Null为新java.math.BigInteger的非null参数传递

时间:2015-10-23 08:56:07

标签: java findbugs

在轰鸣声片段中,为什么FindBugs会抱怨null被传递给BigInteger构造函数?它表示已知的null行:signature=null;

byte[] signature;
Calendar today = new GregorianCalendar(
                        now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE),
                        now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
Date d=today.getTime();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String timestamp =sdf.format(d).toString();
String pp=user.userName+secretKeyStr+timestamp;
try {
    signature = Security.getMD5Hash(pp);
} catch (Exception e) {
    e.printStackTrace();
    signature=null;
}
//convert byte[] into String. method to generate MD5 hash of a string in Java
BigInteger bigInt = new BigInteger(1,signature); 

这是假阳性我在这里错过了什么吗? 我应该在null上退回Exception吗?

1 个答案:

答案 0 :(得分:3)

众所周知,new BigInteger(1,signature); 可以BigInteger行为空。这可能是一个错误,因为如果其中一个参数为null,NullPointerException的构造函数将抛出Exception

您应该以其他方式处理异常,例如返回null(如您所说)。在我看来,您还应该捕获比Dim list(1) As String list(0) = "1" list(1) = "2" With Cells(1, 7).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _ Operator:=xlBetween, Formula1:=Join(list, ",") End With 更具体的例外。