Skip to content

Commit 9a3fa6e

Browse files
philwebbrwinch
authored andcommitted
Simplify boolean returns
Simplify boolean returns of the form: if (b) { return true; } else { return false; } to: return b; Issue gh-8945
1 parent b69825d commit 9a3fa6e

8 files changed

Lines changed: 8 additions & 44 deletions

File tree

‎core/src/main/java/org/springframework/security/access/vote/AuthenticatedVoter.java‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,9 @@ public void setAuthenticationTrustResolver(AuthenticationTrustResolver authentic
6868

6969
@Override
7070
public boolean supports(ConfigAttribute attribute) {
71-
if ((attribute.getAttribute() != null) && (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())
71+
return (attribute.getAttribute() != null) && (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())
7272
|| IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute())
73-
|| IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()))) {
74-
return true;
75-
}
76-
else {
77-
return false;
78-
}
73+
|| IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()));
7974
}
8075

8176
/**

‎core/src/main/java/org/springframework/security/access/vote/RoleVoter.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,7 @@ public void setRolePrefix(String rolePrefix) {
6868

6969
@Override
7070
public boolean supports(ConfigAttribute attribute) {
71-
if ((attribute.getAttribute() != null) && attribute.getAttribute().startsWith(getRolePrefix())) {
72-
return true;
73-
}
74-
else {
75-
return false;
76-
}
71+
return (attribute.getAttribute() != null) && attribute.getAttribute().startsWith(getRolePrefix());
7772
}
7873

7974
/**

‎core/src/main/java/org/springframework/security/core/userdetails/memory/UserAttribute.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ public boolean isEnabled() {
7676
}
7777

7878
public boolean isValid() {
79-
if ((this.password != null) && (this.authorities.size() > 0)) {
80-
return true;
81-
}
82-
else {
83-
return false;
84-
}
79+
return (this.password != null) && (this.authorities.size() > 0);
8580
}
8681

8782
public void setEnabled(boolean enabled) {

‎core/src/test/java/org/springframework/security/access/vote/DenyAgainVoter.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ public class DenyAgainVoter implements AccessDecisionVoter<Object> {
3737

3838
@Override
3939
public boolean supports(ConfigAttribute attribute) {
40-
if ("DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute())) {
41-
return true;
42-
}
43-
else {
44-
return false;
45-
}
40+
return "DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute());
4641
}
4742

4843
@Override

‎core/src/test/java/org/springframework/security/access/vote/DenyVoter.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public class DenyVoter implements AccessDecisionVoter<Object> {
3939

4040
@Override
4141
public boolean supports(ConfigAttribute attribute) {
42-
if ("DENY_FOR_SURE".equals(attribute.getAttribute())) {
43-
return true;
44-
}
45-
else {
46-
return false;
47-
}
42+
return "DENY_FOR_SURE".equals(attribute.getAttribute());
4843
}
4944

5045
@Override

‎etc/checkstyle/checkstyle-suppressions.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
44
"https://checkstyle.org/dtds/suppressions_1_2.dtd">
55
<suppressions>
6-
<suppress files=".*" checks="SimplifyBooleanReturn" />
76
<suppress files=".*" checks="SpringAvoidStaticImport" />
87
<suppress files=".*" checks="SpringCatch" />
98
<suppress files=".*" checks="SpringHeader" />

‎web/src/test/java/org/springframework/security/web/access/channel/ChannelDecisionManagerImplTests.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,7 @@ public void decide(FilterInvocation invocation, Collection<ConfigAttribute> conf
220220

221221
@Override
222222
public boolean supports(ConfigAttribute attribute) {
223-
if (attribute.getAttribute().equals(this.configAttribute)) {
224-
return true;
225-
}
226-
else {
227-
return false;
228-
}
223+
return attribute.getAttribute().equals(this.configAttribute);
229224
}
230225

231226
}

‎web/src/test/java/org/springframework/security/web/access/channel/ChannelProcessingFilterTests.java‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,7 @@ public void decide(FilterInvocation invocation, Collection<ConfigAttribute> conf
170170

171171
@Override
172172
public boolean supports(ConfigAttribute attribute) {
173-
if (attribute.getAttribute().equals(this.supportAttribute)) {
174-
return true;
175-
}
176-
else {
177-
return false;
178-
}
173+
return attribute.getAttribute().equals(this.supportAttribute);
179174
}
180175

181176
}

0 commit comments

Comments
 (0)