From ddb769bf7f144fa365c46533ca58c12bbab94042 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 23 Jan 2024 08:54:52 -0800 Subject: [PATCH] Polish 'Simplify conditionals' See gh-39259 --- .../endpoint/invoke/reflect/OperationMethodParameter.java | 5 ++++- .../devtools/restart/classloader/ClassLoaderFile.java | 8 ++++++-- ...OverrideAutoConfigurationContextCustomizerFactory.java | 2 +- .../boot/loader/net/protocol/jar/JarUrlConnection.java | 6 +++--- .../properties/bind/DefaultBindConstructorProvider.java | 2 +- .../boot/logging/log4j2/SpringProfileArbiter.java | 2 +- .../boot/web/embedded/tomcat/NestedJarResourceSet.java | 2 +- 7 files changed, 17 insertions(+), 10 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java index fdda353e314..6b3e038859b 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/invoke/reflect/OperationMethodParameter.java @@ -68,7 +68,10 @@ class OperationMethodParameter implements OperationParameter { if (!ObjectUtils.isEmpty(this.parameter.getAnnotationsByType(Nullable.class))) { return false; } - return !jsr305Present || new Jsr305().isMandatory(this.parameter); + if (jsr305Present) { + return new Jsr305().isMandatory(this.parameter); + } + return true; } @Override diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFile.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFile.java index 3073b528f47..9972ee76460 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFile.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/classloader/ClassLoaderFile.java @@ -55,8 +55,12 @@ public class ClassLoaderFile implements Serializable { */ public ClassLoaderFile(Kind kind, long lastModified, byte[] contents) { Assert.notNull(kind, "Kind must not be null"); - Assert.isTrue((kind != Kind.DELETED) == (contents != null), - () -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "") + "be null"); + if (kind == Kind.DELETED) { + Assert.isTrue(contents == null, "Contents must be null"); + } + else { + Assert.isTrue(contents != null, "Contents must not be null"); + } this.kind = kind; this.lastModified = lastModified; this.contents = contents; diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java index 06817411d5a..5b7ab2976b2 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java @@ -44,7 +44,7 @@ class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustom } OverrideAutoConfiguration overrideAutoConfiguration = TestContextAnnotationUtils.findMergedAnnotation(testClass, OverrideAutoConfiguration.class); - boolean enabled = overrideAutoConfiguration == null || overrideAutoConfiguration.enabled(); + boolean enabled = (overrideAutoConfiguration == null) || overrideAutoConfiguration.enabled(); return !enabled ? new DisableAutoConfigurationContextCustomizer() : null; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarUrlConnection.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarUrlConnection.java index 2177dae7f16..edc18cd44eb 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarUrlConnection.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/net/protocol/jar/JarUrlConnection.java @@ -207,7 +207,7 @@ final class JarUrlConnection extends java.net.JarURLConnection { @Override public boolean getAllowUserInteraction() { - return this.jarFileConnection != null && this.jarFileConnection.getAllowUserInteraction(); + return (this.jarFileConnection != null) && this.jarFileConnection.getAllowUserInteraction(); } @Override @@ -219,7 +219,7 @@ final class JarUrlConnection extends java.net.JarURLConnection { @Override public boolean getUseCaches() { - return this.jarFileConnection == null || this.jarFileConnection.getUseCaches(); + return (this.jarFileConnection == null) || this.jarFileConnection.getUseCaches(); } @Override @@ -231,7 +231,7 @@ final class JarUrlConnection extends java.net.JarURLConnection { @Override public boolean getDefaultUseCaches() { - return this.jarFileConnection == null || this.jarFileConnection.getDefaultUseCaches(); + return (this.jarFileConnection == null) || this.jarFileConnection.getDefaultUseCaches(); } @Override diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProvider.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProvider.java index a81d38cfd63..33da909ac8a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProvider.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultBindConstructorProvider.java @@ -127,7 +127,7 @@ class DefaultBindConstructorProvider implements BindConstructorProvider { return true; } Class userClass = ClassUtils.getUserClass(type); - return userClass != type && isAutowiredPresent(userClass); + return (userClass != type) && isAutowiredPresent(userClass); } private static Constructor[] getCandidateConstructors(Class type) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java index 461f529f0f8..65dcd3e2d53 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java @@ -53,7 +53,7 @@ final class SpringProfileArbiter implements Arbiter { @Override public boolean isCondition() { - return this.environment != null && this.environment.acceptsProfiles(this.profiles); + return (this.environment != null) && this.environment.acceptsProfiles(this.profiles); } @PluginBuilderFactory diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/NestedJarResourceSet.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/NestedJarResourceSet.java index 77cee0c6a6e..a0a003d2aca 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/NestedJarResourceSet.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/NestedJarResourceSet.java @@ -124,7 +124,7 @@ class NestedJarResourceSet extends AbstractSingleArchiveResourceSet { // JarFile.isMultiRelease() is final so we must go to the manifest Manifest manifest = getManifest(); Attributes attributes = (manifest != null) ? manifest.getMainAttributes() : null; - this.multiRelease = attributes != null && attributes.containsKey(MULTI_RELEASE); + this.multiRelease = (attributes != null) && attributes.containsKey(MULTI_RELEASE); } } }