-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Cleanup #17801
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: main
Are you sure you want to change the base?
Cleanup #17801
Conversation
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
| if (result.length() == 0) { | ||
| if (result.isEmpty()) { | ||
| return null; | ||
| } |
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.
String result = (query == null) ? "" : artifactPattern.matcher(query).replaceFirst("");
if (result.isEmpty()) {
return null;
}
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.
Fair point, @ronodhirSoumik, though the Spring checkstyle requires a negation in ternaries. So, this is probably the result of having run checkstyleTest on the PR.
| * @return | ||
| * @param artifactParameterName the artifactParameterName that is removed from the | ||
| * current URL. The result becomes the service url. Cannot be null and cannot be an | ||
| * empty String. |
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.
Cannot be null and cannot be an empty String -> Cannot be null or empty String
| return role; | ||
| } | ||
| if (defaultRolePrefix == null || defaultRolePrefix.length() == 0) { | ||
| if (defaultRolePrefix == null || defaultRolePrefix.isEmpty()) { |
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.
As there are several uses of str == null || str.isEmpty() I think a common util function will be helpful
boolean isEmpty(String str) {
return str == null || str.length == 0;
}
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 think we can use !org.springframework.util.StringUtils#hasLength
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
ec9b7b9 to
f77e0b9
Compare
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.
Thanks for all the great cleanup, @ngocnhan-tran1996. I've left some feedback inline.
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| if (super.equals(obj)) { |
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.
Let's please stay with this == obj as this is a bit more obvious what kind of shortcut we are doing.
| } | ||
| if (!super.equals(obj) || !(obj instanceof DefaultServiceAuthenticationDetails)) { | ||
| return false; | ||
| if (obj instanceof DefaultServiceAuthenticationDetails that) { |
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.
Thanks for this change. In Spring Security, it's preferred to exit early for simple cases. Would you please flip the logic here to:
if (!(obj instanceof DefaultServiceAuthenticationDetails that)) {
return false;
}
// ... continue| */ | ||
| private String getQueryString(final HttpServletRequest request, final Pattern artifactPattern) { | ||
| final String query = request.getQueryString(); | ||
| if (query == null) { |
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.
Let's please keep checking for null here since that allows us to exit early without needing to instantiate a variable.
| if (result.length() == 0) { | ||
| if (result.isEmpty()) { | ||
| return null; | ||
| } |
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.
Fair point, @ronodhirSoumik, though the Spring checkstyle requires a negation in ternaries. So, this is probably the result of having run checkstyleTest on the PR.
| * @param defaultRolePrefix | ||
| * @param role | ||
| * @return | ||
| * @param defaultRolePrefix the default prefix to add to roles. |
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.
Let's please give an example here since "role prefix" could be a bit esoteric. For example:
the default prefix to add to roles, for example {@code ROLE_}
| import org.springframework.util.StringUtils; | ||
|
|
||
| /** | ||
| * Implementation of PasswordEncoder. |
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 wouldn't quite say that this is an implementation as much as it is an abstract class that allows subclasses to except the password to be non-{@code null}.
Perhaps change this to:
/**
* An abstract {@link PasswordEncoder} that implementers can use for expecting the
* password to be non-{@code null}. Each common password API method is accompanied
* with an abstract method with a {@code NonNull} prefix. By implementing this, the concrete
* class is specifying what to do with the password when it is non-{@code null}, allowing this
* class to handle the {@code null} case.
*
* @author Rob Winch
* @since 7.0
*/| public final boolean upgradeEncoding(@Nullable String encodedPassword) { | ||
| if (encodedPassword == null || encodedPassword.length() == 0) { | ||
| return false; | ||
| if (StringUtils.hasLength(encodedPassword)) { |
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.
Please favor the simpler exits coming first:
if (!StringUtils.hasLength(encodedPassword)) {
return false;
}
return upgradeEncodingNonNull(encodedPassword);This also has the added benefit of making the overall change smaller.
| this.strippedServletPath = strip(request.getServletPath()); | ||
| String pathInfo = strip(request.getPathInfo()); | ||
| if (pathInfo != null && pathInfo.length() == 0) { | ||
| if (pathInfo != null && pathInfo.isEmpty()) { |
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.
Would !StringUtils.hasLength(pathInfo)) work here as well?
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
Signed-off-by: Tran Ngoc Nhan <[email protected]>
This PR includes
StringUtils#hasLength