- Labels: --> report on spotbugs
- Status: open --> closed-rejected
I have the following method in a class that is throwing an error
[INFO] User.passwordCredentials not initialized in constructor and dereferenced in com.xenoterracide.rpf.cm.security.User.encryptPassword(PasswordEncoder) [com.xenoterracide.rpf.cm.security.User] At User.java:[line 49] UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
@Override
public void encryptPassword( final PasswordEncoder encoder ) {
Objects.requireNonNull( encoder );
Objects.requireNonNull( this.passwordCredentials );
this.passwordCredentials.encryptPassword( encoder );
}
but if I do this it's fine
@Override
public void encryptPassword( final PasswordEncoder encoder ) {
Objects.requireNonNull( encoder );
if ( this.passwordCredentials == null ) {
throw new NullPointerException();
}
this.passwordCredentials.encryptPassword( encoder );
}
It's probably worth noting that this is the impl of Objects.requireNonNull which was added in Java 7
public static <T> T requireNonNull(T obj) {
if (obj == null)
throw new NullPointerException();
return obj;
}
Lastly it's worth saying this class is a managed glass (by neo4j and jackson)
I would like findbugs to detect requireNonNull in the same way it detects the obj == null, to know that I did check. Objects.isNull and Objects.nonNull added 8 should also not trigger this check