我的程序中有以下代码,在与 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;
}
最佳答案
你应该这样做:
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);
}
Sonar 不再打扰您
关于java - Sonar 提示记录并重新抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60543807/