Would anyone be so kind as to help me to understand how can I get a null pointer exception here?
@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;
}
Here's what I get at run-time:
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)
...
How can it be? I've just made sure if there's not null
in userRoleCollection
, the next instruction wouldn't have been executed if there was null
, would it?
Thank you very much in advance for your kind help.