java - Java:空检查后的空指针异常
问题描述
有人能帮我理解如何在这里获得空指针异常吗?
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<GrantedAuthority> grantedAuthorityCollection = new ArrayList<>();
Collection<UserRole> userRoleCollection = user.getUserRoleList();
if(userRoleCollection != null) {
if (userDetailsService.getAuthorities(userRoleCollection) != null) {
// ^^^ it occurs at the line above ^^^
grantedAuthorityCollection.addAll(userDetailsService.getAuthorities(userRoleCollection));
}
}
return grantedAuthorityCollection;
}
这是我在运行时得到的:
java.lang.NullPointerException: null
at ua.tucha.passpass.web.security.UserDetails.getAuthorities(UserDetails.java:31)
at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.createSuccessAuthentication(AbstractUserDetailsAuthenticationProvider.java:225)
at org.springframework.security.authentication.dao.DaoAuthenticationProvider.createSuccessAuthentication(DaoAuthenticationProvider.java:137)
at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:197)
...
怎么会这样?我刚刚确定如果没有null
in userRoleCollection
,如果有 ,就不会执行下一条指令,对null
吗?
非常感谢您的帮助。
解决方案
推荐阅读
- react-native - 导航生命周期 ReactNative
- microsoft-teams - Microsoft Teams 中的设置和策略之间的明确关系是什么?
- python - 如何使用 PyPDF2 选择 pdf 格式的单选按钮?
- android - Dagger 无法注入应用程序上下文
- mongoose - 之后如何在猫鼬文件上获得财产?
- python - Django - 重构项目和应用程序名称后没有迁移文件夹
- python - 如何计算无限数量的坐标输入的平均值?
- machine-learning - rapidminer中的逻辑回归最大似然
- ansible - 如果使用“when”,ansible jinja2 模板分隔符会失败
- azure - 与 Azure 密钥保管库集成的应用服务 - 阵列内的配置