From 56cbc65e7b7979cf562021547095a8a9144b4bc0 Mon Sep 17 00:00:00 2001 From: igor-suhorukov Date: Tue, 27 Feb 2018 01:08:28 +0300 Subject: [PATCH 1/2] Polish See gh-12236 --- .../BackgroundPreinitializer.java | 7 +++--- .../EmbeddedLdapAutoConfiguration.java | 9 ++++---- ...ditionEvaluationReportLoggingListener.java | 7 +++--- .../session/SessionAutoConfiguration.java | 15 ++++++------ .../boot/cli/command/install/Installer.java | 8 +++---- .../boot/cli/compiler/AstUtils.java | 9 ++++---- .../boot/cli/util/ResourceUtils.java | 9 ++++---- .../fieldvalues/javac/Tree.java | 16 ++++++------- .../boot/loader/jar/JarURLConnection.java | 7 +++--- .../boot/BeanDefinitionLoader.java | 10 ++++---- ...arentContextCloserApplicationListener.java | 11 ++++----- .../context/ApplicationPidFileWriter.java | 23 +++++++++---------- .../SpringBootConfigurationFactory.java | 7 +++--- 13 files changed, 61 insertions(+), 77 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java index 3d4a697224a..bdb648bd6e7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java @@ -56,10 +56,9 @@ public class BackgroundPreinitializer @Override public void onApplicationEvent(SpringApplicationEvent event) { - if (event instanceof ApplicationStartingEvent) { - if (preinitializationStarted.compareAndSet(false, true)) { - performPreinitialization(); - } + if (event instanceof ApplicationStartingEvent + && preinitializationStarted.compareAndSet(false, true)) { + performPreinitialization(); } if ((event instanceof ApplicationReadyEvent || event instanceof ApplicationFailedEvent) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java index c759660dbc4..46c3615d2d6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/ldap/embedded/EmbeddedLdapAutoConfiguration.java @@ -218,13 +218,12 @@ public class EmbeddedLdapAutoConfiguration { AnnotatedTypeMetadata metadata) { Builder message = ConditionMessage.forCondition("Embedded LDAP"); Environment environment = context.getEnvironment(); - if (environment != null) { - if (!Binder.get(environment) + if (environment != null + && !Binder.get(environment) .bind("spring.ldap.embedded.base-dn", STRING_LIST) .orElseGet(Collections::emptyList).isEmpty()) { - return ConditionOutcome - .match(message.because("Found base-dn property")); - } + return ConditionOutcome + .match(message.because("Found base-dn property")); } return ConditionOutcome.noMatch(message.because("No base-dn property found")); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java index b3c01c1adc9..9913562e5e8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java @@ -74,11 +74,10 @@ public class ConditionEvaluationReportLoggingListener logAutoConfigurationReport(); } } - else if (event instanceof ApplicationFailedEvent) { - if (((ApplicationFailedEvent) event) + else if (event instanceof ApplicationFailedEvent + && ((ApplicationFailedEvent) event) .getApplicationContext() == initializerApplicationContext) { - logAutoConfigurationReport(true); - } + logAutoConfigurationReport(true); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java index e500fdd89c6..3025b329c3d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/session/SessionAutoConfiguration.java @@ -248,14 +248,13 @@ public class SessionAutoConfiguration { public void checkSessionRepository() { StoreType storeType = this.sessionProperties.getStoreType(); if (storeType != StoreType.NONE - && this.sessionRepositoryProvider.getIfAvailable() == null) { - if (storeType != null) { - throw new SessionRepositoryUnavailableException( - "No session repository could be auto-configured, check your " - + "configuration (session store type is '" - + storeType.name().toLowerCase(Locale.ENGLISH) + "')", - storeType); - } + && this.sessionRepositoryProvider.getIfAvailable() == null + && storeType != null) { + throw new SessionRepositoryUnavailableException( + "No session repository could be auto-configured, check your " + + "configuration (session store type is '" + + storeType.name().toLowerCase(Locale.ENGLISH) + "')", + storeType); } } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java index ff5f3925703..78ad5b5d50a 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java @@ -147,11 +147,9 @@ class Installer { String home = SystemPropertyUtils .resolvePlaceholders("${spring.home:${SPRING_HOME:.}}"); File extDirectory = new File(new File(home, "lib"), "ext"); - if (!extDirectory.isDirectory()) { - if (!extDirectory.mkdirs()) { - throw new IllegalStateException( - "Failed to create ext directory " + extDirectory); - } + if (!extDirectory.isDirectory() && !extDirectory.mkdirs()) { + throw new IllegalStateException( + "Failed to create ext directory " + extDirectory); } return extDirectory; } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java index 8db6716d5c2..23cd31b2714 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/AstUtils.java @@ -179,11 +179,10 @@ public abstract class AstUtils { private static ClosureExpression getClosure(String name, MethodCallExpression expression) { Expression method = expression.getMethod(); - if (method instanceof ConstantExpression) { - if (name.equals(((ConstantExpression) method).getValue())) { - return (ClosureExpression) ((ArgumentListExpression) expression - .getArguments()).getExpression(0); - } + if (method instanceof ConstantExpression + && name.equals(((ConstantExpression) method).getValue())) { + return (ClosureExpression) ((ArgumentListExpression) expression + .getArguments()).getExpression(0); } return null; } diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java index c64a8afb3dc..f764493da91 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/ResourceUtils.java @@ -103,11 +103,10 @@ public abstract class ResourceUtils { List result = new ArrayList<>(); for (Resource resource : resources) { if (resource.exists()) { - if (resource.getURI().getScheme().equals("file")) { - if (resource.getFile().isDirectory()) { - result.addAll(getChildFiles(resource)); - continue; - } + if (resource.getURI().getScheme().equals("file") + && resource.getFile().isDirectory()) { + result.addAll(getChildFiles(resource)); + continue; } result.add(absolutePath(resource)); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Tree.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Tree.java index 5e555365a72..39853472615 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Tree.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Tree.java @@ -63,15 +63,13 @@ class Tree extends ReflectionWrapper { @SuppressWarnings("rawtypes") public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if (method.getName().equals("visitClass")) { - if ((Integer) args[1] == 0) { - Iterable members = (Iterable) Tree.this.getClassTreeMembers - .invoke(args[0]); - for (Object member : members) { - if (member != null) { - Tree.this.acceptMethod.invoke(member, proxy, - ((Integer) args[1]) + 1); - } + if (method.getName().equals("visitClass") && (Integer) args[1] == 0) { + Iterable members = (Iterable) Tree.this.getClassTreeMembers + .invoke(args[0]); + for (Object member : members) { + if (member != null) { + Tree.this.acceptMethod.invoke(member, proxy, + ((Integer) args[1]) + 1); } } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 719457ee4ce..22380b481f9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -266,11 +266,10 @@ final class JarURLConnection extends java.net.JarURLConnection { index = separator + SEPARATOR.length(); } JarEntryName jarEntryName = JarEntryName.get(spec, index); - if (Boolean.TRUE.equals(useFastExceptions.get())) { - if (!jarEntryName.isEmpty() + if (Boolean.TRUE.equals(useFastExceptions.get()) + && !jarEntryName.isEmpty() && !jarFile.containsEntry(jarEntryName.toString())) { - return NOT_FOUND_CONNECTION; - } + return NOT_FOUND_CONNECTION; } return new JarURLConnection(url, jarFile, jarEntryName); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java index c7def2c319f..71d07659271 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java @@ -147,13 +147,11 @@ class BeanDefinitionLoader { } private int load(Class source) { - if (isGroovyPresent()) { + if (isGroovyPresent() && GroovyBeanDefinitionSource.class.isAssignableFrom(source)) { // Any GroovyLoaders added in beans{} DSL can contribute beans here - if (GroovyBeanDefinitionSource.class.isAssignableFrom(source)) { - GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source, - GroovyBeanDefinitionSource.class); - load(loader); - } + GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source, + GroovyBeanDefinitionSource.class); + load(loader); } if (isComponent(source)) { this.annotatedReader.register(source); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java index ad95daa3c39..7bb2da2f0d1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java @@ -60,12 +60,11 @@ public class ParentContextCloserApplicationListener } private void maybeInstallListenerInParent(ConfigurableApplicationContext child) { - if (child == this.context) { - if (child.getParent() instanceof ConfigurableApplicationContext) { - ConfigurableApplicationContext parent = (ConfigurableApplicationContext) child - .getParent(); - parent.addApplicationListener(createContextCloserListener(child)); - } + if (child == this.context + && child.getParent() instanceof ConfigurableApplicationContext) { + ConfigurableApplicationContext parent = (ConfigurableApplicationContext) child + .getParent(); + parent.addApplicationListener(createContextCloserListener(child)); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java index a5e9187bbad..ab3a5fe4ae1 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/ApplicationPidFileWriter.java @@ -136,19 +136,18 @@ public class ApplicationPidFileWriter @Override public void onApplicationEvent(SpringApplicationEvent event) { - if (this.triggerEventType.isInstance(event)) { - if (created.compareAndSet(false, true)) { - try { - writePidFile(event); - } - catch (Exception ex) { - String message = String.format("Cannot create pid file %s", - this.file); - if (failOnWriteError(event)) { - throw new IllegalStateException(message, ex); - } - logger.warn(message, ex); + if (this.triggerEventType.isInstance(event) + && created.compareAndSet(false, true)) { + try { + writePidFile(event); + } + catch (Exception ex) { + String message = String.format("Cannot create pid file %s", + this.file); + if (failOnWriteError(event)) { + throw new IllegalStateException(message, ex); } + logger.warn(message, ex); } } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java index 9d840c54b26..aae778f1bdf 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java @@ -51,10 +51,9 @@ public class SpringBootConfigurationFactory extends ConfigurationFactory { @Override public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) { - if (source != null && source != ConfigurationSource.NULL_SOURCE) { - if (LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) { - return new DefaultConfiguration(); - } + if (source != null && source != ConfigurationSource.NULL_SOURCE + && LoggingSystem.get(loggerContext.getClass().getClassLoader()) != null) { + return new DefaultConfiguration(); } return null; } From 4180762d6d92207aa42de7c5500a556c6e5a59e6 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 28 Feb 2018 09:01:59 +0100 Subject: [PATCH 2/2] Polish contribution Closes gh-12236 --- .../logging/ConditionEvaluationReportLoggingListener.java | 2 +- .../springframework/boot/cli/command/install/Installer.java | 2 +- .../org/springframework/boot/loader/jar/JarURLConnection.java | 2 +- .../java/org/springframework/boot/BeanDefinitionLoader.java | 3 ++- .../boot/builder/ParentContextCloserApplicationListener.java | 2 +- .../boot/logging/log4j2/SpringBootConfigurationFactory.java | 2 +- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java index 9913562e5e8..07db103fb83 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/logging/ConditionEvaluationReportLoggingListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java index 78ad5b5d50a..ccbaab608d1 100644 --- a/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java +++ b/spring-boot-project/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/install/Installer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java index 22380b481f9..bdfd1b75eb9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/JarURLConnection.java @@ -268,7 +268,7 @@ final class JarURLConnection extends java.net.JarURLConnection { JarEntryName jarEntryName = JarEntryName.get(spec, index); if (Boolean.TRUE.equals(useFastExceptions.get()) && !jarEntryName.isEmpty() - && !jarFile.containsEntry(jarEntryName.toString())) { + && !jarFile.containsEntry(jarEntryName.toString())) { return NOT_FOUND_CONNECTION; } return new JarURLConnection(url, jarFile, jarEntryName); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java index 71d07659271..7089669307f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/BeanDefinitionLoader.java @@ -147,7 +147,8 @@ class BeanDefinitionLoader { } private int load(Class source) { - if (isGroovyPresent() && GroovyBeanDefinitionSource.class.isAssignableFrom(source)) { + if (isGroovyPresent() + && GroovyBeanDefinitionSource.class.isAssignableFrom(source)) { // Any GroovyLoaders added in beans{} DSL can contribute beans here GroovyBeanDefinitionSource loader = BeanUtils.instantiateClass(source, GroovyBeanDefinitionSource.class); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java index 7bb2da2f0d1..9f69bd5dd27 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/builder/ParentContextCloserApplicationListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java index aae778f1bdf..213f40ab4e6 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringBootConfigurationFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.