我在我的程序中有以下代码片段,并且在与Maven集成之后,我正在运行SonarQube 5以进行代码质量检查.
但是,Sonar要求将封闭方法设为"静态"或删除此设置.方法是setApplicationContext.
如何删除此错误?为什么会出现这个错误?
public class SharedContext implements ApplicationContextAware {
public static final String REPORT_ENGINE_FACTORY = "reportEngineFactory";
private static ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
SharedContext.applicationContext = applicationContext;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
public Object getBean(String name) {
return applicationContext.getBean(name);
} }
Run Code Online (Sandbox Code Playgroud) 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.");
}
Run Code Online (Sandbox Code Playgroud)
我在第4行和第7行遇到此错误(用户名== null和密码== null)
我需要在我的代码中使用这一部分.我正在尝试isEmpty()而不是null,但也面临着问题.什么是解决此SONAR错误的替代方法或解决方案
我在我的程序中有以下代码片段,并且在与Maven集成之后,我正在运行SonarQube 5以进行代码质量检查.
但是,Sonar要求将此无用的赋值移除到局部变量"session".
@RequestMapping(value = "/logoff", method = RequestMethod.GET)
public String getLogoffPage(HttpServletRequest request, HttpServletResponse response) {
logger.info(" Before Log Offf........ " + request.getSession().getId() );
HttpSession session =request.getSession(true);
request.getSession().invalidate();
myApplication.logout();
SecurityContextHolder.clearContext();
session=null;
return "login";
}
Run Code Online (Sandbox Code Playgroud)