Findbugs Unchecked/unconfirmed 从构建器风格的链式函数调用中转换

Findbugs Unchecked/unconfirmed cast from builder style chained function calls

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

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

代码工作正常,我该如何安抚 FindBugs?

编辑:

正如@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");
}

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