Say I have the following method definition in a Spring service layer:
@Override
public boolean passwordsMatch(String encrypted, String plain) {
if (encrypted == null || encrypted.isEmpty() || plain == null || plain.isEmpty()) {
throw new IllegalArgumentException("One argument is null or empty");
}
return passwordEncoder.matches(plain, encrypted);
}
It is called by a Spring MVC application controller that wants to check whether the new password provided by a user (here called "plain") matches the user's current password (here called "encrypted").
Should I really be throwing an IllegalArgumentException (or any subtype of RuntimeException) if the new password provided by the user is empty (plain.isEmpty()
)?
I am 95% sure I am going to remove this check but I'd be curious to hear arguments in favor of keeping the check in this particular case.