为新java.math.BigInteger的非Null参数传递了FindBugs Null
在下面的代码段中,FindBugs为什么抱怨为新java.math.BigInteger的非Null参数传递了FindBugs Null,java,findbugs,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),
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);
这是假阳性还是我遗漏了什么?
我应该在Exception
上返回null
众所周知,签名
可以在新的BigInteger(1,签名)处为空代码>行。这可能是一个错误,因为如果其中一个参数为null,则biginger
的构造函数将抛出NullPointerException
您应该以其他方式处理异常,例如返回null(如您所说)。在我看来,您还应该捕获比异常
更具体的异常