声纳抱怨记录和重新排列异常 [英] Sonar complaining about logging and rethrowing the exception
本文介绍了声纳抱怨记录和重新排列异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
但是,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(在用户名为user + user.getUsername()+和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(用户名称为用户验证用户凭据时出现异常+
user.getUsername()+和pwd:+ user。 getPwd(),sqle);
}
声纳不应该打扰你
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.
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;
}
解决方案
You should do it this way :
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 shouldn't bother you anymore
这篇关于声纳抱怨记录和重新排列异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文