I saw an example where the following syntax was used in a customer validator inside a LoginCommand object.
password blank:false, validator: { val, cmd ->
if(cmd.user && cmd.user.password != val)
return "user.password.invalid"
}
My understanding is that here in the if clause, we are checking two things. First, that a user exists, and second, that the password of the user matches the password held by the LoginCommand. Doesn't it seem redundant to check if the user exists? I mean if the user didn't exist wouldn't cmd.user.password be null and hence the test would fail? Why is the user check necessary?
And if it is necessary, then can't we encapsulate the first user existence check in the second check using this syntax cmd.user?.password != val?