我在我的程序中有以下代码片段,并且在与Maven集成之后,我正在运行SonarQube 5以进行代码质量检查.
然而,Sonar抱怨我应该记录或重新抛出此异常.
我在这里错过了什么?我还没有记录异常吗?
private boolean authenticate(User user) {
boolean validUser = false;
int validUserCount = 0;
try {
DataSource dataSource = (DataSource) getServletContext().getAttribute("dataSource");
validUserCount = new MasterDao(dataSource).getValidUserCount(user);
} catch (SQLException sqle) {
LOG.error("Exception while validating user credentials for user with username: " + user.getUsername() + " and pwd:" + user.getPwd());
LOG.error(sqle.getMessage());
}
if (validUserCount == 1) {
validUser = true;
}
return validUser;
}
Run Code Online (Sandbox Code Playgroud) 有人可以帮我解释为什么 SonarLint 会显示这个:
要么记录此异常并处理它,要么使用一些上下文信息重新抛出它。
对于下面的代码。
public static <T> T getObjectFromJson(final Object jsonString, final Class<T> valueType) {
T object = null;
if (jsonString != null) {
try {
object = MAPPER.readValue(jsonString.toString(), valueType);
} catch (IOException io) {
log.error(ERROR_LOG_STR + " in method getObjectFromJson(). Exception Message={}, Exception Stack ={}",
io.getMessage(), io);
throw new ServiceException(ErrorMessages.JSON_SERIALIZATION_ERROR, io.getCause());
}
}
return object;
}
Run Code Online (Sandbox Code Playgroud)