1

FindBugs 报告了以下用于配置 Spring 安全性的构建器模式代码中的 and() 行的 Unchecked/Unconfirmed cast 问题。

public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
        .inMemoryAuthentication()
            .withUser("admin").password("secret").roles("ADMIN")
                .and()
            .withUser("user").password("secret").roles("USER");
}

代码运行良好,我该如何安抚 FindBugs?

4

1 回答 1

-1

编辑:

正如@h3xStream(在下面的评论中)所建议的那样,如果您在使用任何代码分析工具时遇到误报,最好的解决方案是将该工具配置为忽略误报并采取措施纠正代码分析工具。这当然假设它确实是一个误报,并且您的代码以其当前形式是正确的并且最好保持不变。

在紧要关头,您也许可以重写代码以防止误报被触发。这就是我最终在这种特殊情况下所做的事情,尽管它实际上只是一种解决方法:


通过将代码更新为以下内容,我能够阻止误报被触发:

public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> conf 
            = auth.inMemoryAuthentication();
    conf.withUser("admin").password("secret").roles("ADMIN");
    conf.withUser("user").password("secret").roles("USER");
}

由于我不再将函数链接在一起,因此返回值变得无关紧要,并且不再触发误报。

于 2018-03-04T00:35:30.557 回答