-
Notifications
You must be signed in to change notification settings - Fork 4.2k
TRUNK-6519: Fix NPE when validating Role with null name #5684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |||||||
| */ | ||||||||
| @Handler(supports = { Role.class }, order = 50) | ||||||||
| public class RoleValidator implements Validator { | ||||||||
|
|
||||||||
| /** | ||||||||
| * Determines if the command object being submitted is a valid type | ||||||||
| * | ||||||||
|
|
@@ -32,19 +32,22 @@ public class RoleValidator implements Validator { | |||||||
| public boolean supports(Class<?> c) { | ||||||||
| return c.equals(Role.class); | ||||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Checks the form object for any inconsistencies/errors | ||||||||
| * | ||||||||
| * @see org.springframework.validation.Validator#validate(java.lang.Object, | ||||||||
| * org.springframework.validation.Errors) | ||||||||
| * <strong>Should</strong> throw NullPointerException if role is null | ||||||||
| * <strong>Should</strong> fail validation if role is empty or whitespace | ||||||||
| * <strong>Should</strong> pass validation if description is null or empty or whitespace | ||||||||
| * <strong>Should</strong> fail validation if role has leading or trailing space | ||||||||
| * <strong>Should</strong> pass validation if all required fields have proper values | ||||||||
| * <strong>Should</strong> pass validation if field lengths are correct | ||||||||
| * <strong>Should</strong> fail validation if field lengths are not correct | ||||||||
| * <strong>Should</strong> fail validation if role is null | ||||||||
| * <strong>Should</strong> fail validation if role is empty or whitespace | ||||||||
| * <strong>Should</strong> pass validation if description is null or empty | ||||||||
| * or whitespace | ||||||||
| * <strong>Should</strong> fail validation if role has leading or trailing | ||||||||
| * space | ||||||||
| * <strong>Should</strong> pass validation if all required fields have | ||||||||
| * proper values | ||||||||
dineshsuthar123 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| * <strong>Should</strong> pass validation if field lengths are correct | ||||||||
| * <strong>Should</strong> fail validation if field lengths are not correct | ||||||||
| */ | ||||||||
| @Override | ||||||||
| public void validate(Object obj, Errors errors) { | ||||||||
|
|
@@ -53,9 +56,9 @@ public void validate(Object obj, Errors errors) { | |||||||
| errors.rejectValue("role", "error.general"); | ||||||||
| } else { | ||||||||
| ValidationUtils.rejectIfEmptyOrWhitespace(errors, "role", "error.role"); | ||||||||
|
|
||||||||
| // reject any role that has a leading or trailing space | ||||||||
| if (!role.getRole().equals(role.getRole().trim())) { | ||||||||
| if (role.getRole() != null && !role.getRole().equals(role.getRole().trim())) { | ||||||||
|
||||||||
| if (role.getRole() != null && !role.getRole().equals(role.getRole().trim())) { | |
| String roleName = role.getRole(); | |
| if (roleName != null && !roleName.equals(roleName.trim())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly for readability, is it okay to store role.getRole() in a local variable instead of calling it multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve updated the code to store role.getRole() in a local variable for improved readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve applied the readability improvements where the repeated calls occurred and cleaned up the related Javadoc.
If there’s any other specific section you’d like me to update for consistency, please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same applies here and the rest of the files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we discard these formatting changes?