From 65a1ff84e6b5ff63a734f1d0abc618137da9d95c Mon Sep 17 00:00:00 2001 From: Tobias Lippert Date: Sun, 21 Jan 2024 18:44:32 +0100 Subject: [PATCH] Simplify conditionals See gh-39259 --- .../endpoint/invoke/reflect/OperationMethodParameter.java | 2 +- .../boot/devtools/restart/classloader/ClassLoaderFile.java | 2 +- .../OverrideAutoConfigurationContextCustomizerFactory.java | 2 +- .../boot/loader/net/protocol/jar/JarUrlConnection.java | 6 +++--- .../NotConstructorBoundInjectionFailureAnalyzer.java | 4 ++-- .../properties/bind/DefaultBindConstructorProvider.java | 2 +- .../boot/logging/log4j2/SpringProfileArbiter.java | 2 +- .../boot/web/embedded/tomcat/NestedJarResourceSet.java | 2 +- 8 files changed, 11 insertions(+), 11 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 a4fa71ebe62..fdda353e314 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,7 @@ class OperationMethodParameter implements OperationParameter { if (!ObjectUtils.isEmpty(this.parameter.getAnnotationsByType(Nullable.class))) { return false; } - return (jsr305Present) ? new Jsr305().isMandatory(this.parameter) : true; + return !jsr305Present || new Jsr305().isMandatory(this.parameter); } @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 d39c569e5eb..3073b528f47 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,7 +55,7 @@ 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 == null, + Assert.isTrue((kind != Kind.DELETED) == (contents != null), () -> "Contents must " + ((kind != Kind.DELETED) ? "not " : "") + "be null"); this.kind = kind; this.lastModified = lastModified; 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 664e1e035d9..06817411d5a 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() : true; + 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 c39bd37a44f..2177dae7f16 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() : false; + 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() : true; + 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() : true; + return this.jarFileConnection == null || this.jarFileConnection.getDefaultUseCaches(); } @Override diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java index 228aa5ed48c..548eb266bae 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/NotConstructorBoundInjectionFailureAnalyzer.java @@ -61,8 +61,8 @@ class NotConstructorBoundInjectionFailureAnalyzer } private boolean isConstructorBindingConfigurationProperties(InjectionPoint injectionPoint) { - return (injectionPoint != null && injectionPoint.getMember() instanceof Constructor constructor) - ? isConstructorBindingConfigurationProperties(constructor) : false; + return injectionPoint != null && injectionPoint.getMember() instanceof Constructor constructor + && isConstructorBindingConfigurationProperties(constructor); } private boolean isConstructorBindingConfigurationProperties(Constructor constructor) { 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 609b8ebccc3..a81d38cfd63 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) : false; + 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 6aa7f5421af..461f529f0f8 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) : false; + 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 0f1be9560a9..77cee0c6a6e 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) : false; + this.multiRelease = attributes != null && attributes.containsKey(MULTI_RELEASE); } } }