瀏覽代碼

Simplify boolean returns

Simplify boolean returns of the form:

	if (b) {
		return true;
	} else {
		return false;
	}

to:

	return b;

Issue gh-8945
Phillip Webb 5 年之前
父節點
當前提交
9a3fa6e812

+ 2 - 7
core/src/main/java/org/springframework/security/access/vote/AuthenticatedVoter.java

@@ -68,14 +68,9 @@ public class AuthenticatedVoter implements AccessDecisionVoter<Object> {
 
 	@Override
 	public boolean supports(ConfigAttribute attribute) {
-		if ((attribute.getAttribute() != null) && (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())
+		return (attribute.getAttribute() != null) && (IS_AUTHENTICATED_FULLY.equals(attribute.getAttribute())
 				|| IS_AUTHENTICATED_REMEMBERED.equals(attribute.getAttribute())
-				|| IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()))) {
-			return true;
-		}
-		else {
-			return false;
-		}
+				|| IS_AUTHENTICATED_ANONYMOUSLY.equals(attribute.getAttribute()));
 	}
 
 	/**

+ 1 - 6
core/src/main/java/org/springframework/security/access/vote/RoleVoter.java

@@ -68,12 +68,7 @@ public class RoleVoter implements AccessDecisionVoter<Object> {
 
 	@Override
 	public boolean supports(ConfigAttribute attribute) {
-		if ((attribute.getAttribute() != null) && attribute.getAttribute().startsWith(getRolePrefix())) {
-			return true;
-		}
-		else {
-			return false;
-		}
+		return (attribute.getAttribute() != null) && attribute.getAttribute().startsWith(getRolePrefix());
 	}
 
 	/**

+ 1 - 6
core/src/main/java/org/springframework/security/core/userdetails/memory/UserAttribute.java

@@ -76,12 +76,7 @@ public class UserAttribute {
 	}
 
 	public boolean isValid() {
-		if ((this.password != null) && (this.authorities.size() > 0)) {
-			return true;
-		}
-		else {
-			return false;
-		}
+		return (this.password != null) && (this.authorities.size() > 0);
 	}
 
 	public void setEnabled(boolean enabled) {

+ 1 - 6
core/src/test/java/org/springframework/security/access/vote/DenyAgainVoter.java

@@ -37,12 +37,7 @@ public class DenyAgainVoter implements AccessDecisionVoter<Object> {
 
 	@Override
 	public boolean supports(ConfigAttribute attribute) {
-		if ("DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute())) {
-			return true;
-		}
-		else {
-			return false;
-		}
+		return "DENY_AGAIN_FOR_SURE".equals(attribute.getAttribute());
 	}
 
 	@Override

+ 1 - 6
core/src/test/java/org/springframework/security/access/vote/DenyVoter.java

@@ -39,12 +39,7 @@ public class DenyVoter implements AccessDecisionVoter<Object> {
 
 	@Override
 	public boolean supports(ConfigAttribute attribute) {
-		if ("DENY_FOR_SURE".equals(attribute.getAttribute())) {
-			return true;
-		}
-		else {
-			return false;
-		}
+		return "DENY_FOR_SURE".equals(attribute.getAttribute());
 	}
 
 	@Override

+ 0 - 1
etc/checkstyle/checkstyle-suppressions.xml

@@ -3,7 +3,6 @@
 		"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
 		"https://checkstyle.org/dtds/suppressions_1_2.dtd">
 <suppressions>
-	<suppress files=".*" checks="SimplifyBooleanReturn" />
 	<suppress files=".*" checks="SpringAvoidStaticImport" />
 	<suppress files=".*" checks="SpringCatch" />
 	<suppress files=".*" checks="SpringHeader" />

+ 1 - 6
web/src/test/java/org/springframework/security/web/access/channel/ChannelDecisionManagerImplTests.java

@@ -220,12 +220,7 @@ public class ChannelDecisionManagerImplTests {
 
 		@Override
 		public boolean supports(ConfigAttribute attribute) {
-			if (attribute.getAttribute().equals(this.configAttribute)) {
-				return true;
-			}
-			else {
-				return false;
-			}
+			return attribute.getAttribute().equals(this.configAttribute);
 		}
 
 	}

+ 1 - 6
web/src/test/java/org/springframework/security/web/access/channel/ChannelProcessingFilterTests.java

@@ -170,12 +170,7 @@ public class ChannelProcessingFilterTests {
 
 		@Override
 		public boolean supports(ConfigAttribute attribute) {
-			if (attribute.getAttribute().equals(this.supportAttribute)) {
-				return true;
-			}
-			else {
-				return false;
-			}
+			return attribute.getAttribute().equals(this.supportAttribute);
 		}
 
 	}