【发布时间】:2017-01-22 07:33:51
【问题描述】:
public String generateURLSafeToken(String username, char[] password) throws CredentialTokenException {
this.tokenValid = false;
String token = null;
if ((username.length() < 1) || (username == null)) {
throw new CredentialTokenException("Username cannot be an empty string or null.");
}
if ((password.length < 1) || (password == null)) {
throw new CredentialTokenException("Password cannot be an empty or null.");
}
我在第 4 行和第 7 行遇到此错误(用户名 == null 和密码 == null)
我的代码中需要这部分。我正在尝试 isEmpty() 而不是 null 但也面临着问题。解决此 SONAR 错误的替代方法或解决方案是什么
【问题讨论】:
-
交换条件。在测试长度之前,您应该检查
null。