我的程序中有以下代码,在将其与 Maven 集成后,我正在运行 SonarQube 5 以对其进行代码质量检查.
I have the following piece of code in my program and I am running SonarQube 5 for code quality check on it after integrating it with Maven.
但是,Sonar 抱怨我应该记录或重新抛出此异常.
However, Sonar is complaining that I should Either log or rethrow this exception.
我在这里缺少什么?我还没有记录异常吗?
What am I missing here? Am I not already logging the exception?
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;
}
你应该这样做:
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(), sqle);
}
声纳不应该再打扰你了
这篇关于声纳抱怨记录并重新抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!