Skip to content

Commit 23fa294

Browse files
Use String#isEmpty
Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent 36f1de9 commit 23fa294

File tree

9 files changed

+11
-12
lines changed

9 files changed

+11
-12
lines changed

cas/src/main/java/org/springframework/security/cas/web/authentication/DefaultServiceAuthenticationDetails.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private String getQueryString(final HttpServletRequest request, final Pattern ar
110110
return null;
111111
}
112112
String result = artifactPattern.matcher(query).replaceFirst("");
113-
if (result.length() == 0) {
113+
if (result.isEmpty()) {
114114
return null;
115115
}
116116
// strip off the trailing & only if the artifact was the first query param

core/src/main/java/org/springframework/security/access/annotation/Jsr250MethodSecurityMetadataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private String getRoleWithDefaultPrefix(String role) {
108108
if (role == null) {
109109
return role;
110110
}
111-
if (this.defaultRolePrefix == null || this.defaultRolePrefix.length() == 0) {
111+
if (this.defaultRolePrefix == null || this.defaultRolePrefix.isEmpty()) {
112112
return role;
113113
}
114114
if (role.startsWith(this.defaultRolePrefix)) {

core/src/main/java/org/springframework/security/access/expression/SecurityExpressionRoot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private static String getRoleWithDefaultPrefix(@Nullable String defaultRolePrefi
236236
if (role == null) {
237237
return role;
238238
}
239-
if (defaultRolePrefix == null || defaultRolePrefix.length() == 0) {
239+
if (defaultRolePrefix == null || defaultRolePrefix.isEmpty()) {
240240
return role;
241241
}
242242
if (role.startsWith(defaultRolePrefix)) {

crypto/src/main/java/org/springframework/security/crypto/password/AbstractValidatingPasswordEncoder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public abstract class AbstractValidatingPasswordEncoder implements PasswordEncod
3232

3333
@Override
3434
public final boolean matches(@Nullable CharSequence rawPassword, @Nullable String encodedPassword) {
35-
if (rawPassword == null || rawPassword.length() == 0 || encodedPassword == null
36-
|| encodedPassword.length() == 0) {
35+
if (rawPassword == null || rawPassword.isEmpty() || encodedPassword == null || encodedPassword.isEmpty()) {
3736
return false;
3837
}
3938
return matchesNonNull(rawPassword.toString(), encodedPassword);
@@ -43,7 +42,7 @@ public final boolean matches(@Nullable CharSequence rawPassword, @Nullable Strin
4342

4443
@Override
4544
public final boolean upgradeEncoding(@Nullable String encodedPassword) {
46-
if (encodedPassword == null || encodedPassword.length() == 0) {
45+
if (encodedPassword == null || encodedPassword.isEmpty()) {
4746
return false;
4847
}
4948
return upgradeEncodingNonNull(encodedPassword);

web/src/main/java/org/springframework/security/web/authentication/rememberme/AbstractRememberMeServices.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public Authentication autoLogin(HttpServletRequest request, HttpServletResponse
129129
return null;
130130
}
131131
this.logger.debug("Remember-me cookie detected");
132-
if (rememberMeCookie.length() == 0) {
132+
if (rememberMeCookie.isEmpty()) {
133133
this.logger.debug("Cookie was empty");
134134
cancelCookie(request, response);
135135
return null;
@@ -382,7 +382,7 @@ protected void setCookie(String[] tokens, int maxAge, HttpServletRequest request
382382

383383
private String getCookiePath(HttpServletRequest request) {
384384
String contextPath = request.getContextPath();
385-
return (contextPath.length() > 0) ? contextPath : "/";
385+
return contextPath.isEmpty() ? "/" : contextPath;
386386
}
387387

388388
/**

web/src/main/java/org/springframework/security/web/firewall/RequestWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ final class RequestWrapper extends FirewalledRequest {
5656
super(request);
5757
this.strippedServletPath = strip(request.getServletPath());
5858
String pathInfo = strip(request.getPathInfo());
59-
if (pathInfo != null && pathInfo.length() == 0) {
59+
if (pathInfo != null && pathInfo.isEmpty()) {
6060
pathInfo = null;
6161
}
6262
this.strippedPathInfo = pathInfo;

web/src/main/java/org/springframework/security/web/savedrequest/DefaultSavedRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ private static String createQueryString(String queryString, String matchingReque
378378
if (matchingRequestParameterName == null) {
379379
return queryString;
380380
}
381-
if (queryString == null || queryString.length() == 0) {
381+
if (queryString == null || queryString.isEmpty()) {
382382
return matchingRequestParameterName;
383383
}
384384
return UriComponentsBuilder.newInstance()

web/src/main/java/org/springframework/security/web/util/TextEscapeUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public abstract class TextEscapeUtils {
2626

2727
public static String escapeEntities(String s) {
28-
if (s == null || s.length() == 0) {
28+
if (s == null || s.isEmpty()) {
2929
return s;
3030
}
3131
StringBuilder sb = new StringBuilder();

web/src/test/java/org/springframework/security/web/firewall/RequestWrapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void pathParametersAreRemovedFromPathInfo() {
7373
String path = entry.getKey();
7474
String expectedResult = entry.getValue();
7575
// Should be null when stripped value is empty
76-
if (expectedResult.length() == 0) {
76+
if (expectedResult.isEmpty()) {
7777
expectedResult = null;
7878
}
7979
request.setPathInfo(path);

0 commit comments

Comments
 (0)