From 56544c8dd5dd5af7e19e10ebae2861123e83dec0 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Fri, 9 Sep 2016 10:27:44 -0700 Subject: [PATCH] Polish --- .../autoconfigure/orm/jpa/JpaBaseConfiguration.java | 6 +++--- .../AbstractTemplateResolverConfiguration.java | 6 +++++- .../thymeleaf/ThymeleafAutoConfiguration.java | 7 ++++--- .../autoconfigure/thymeleaf/ThymeleafProperties.java | 2 +- .../autoconfigure/web/MultipartAutoConfiguration.java | 2 +- .../boot/autoconfigure/web/MultipartProperties.java | 2 +- spring-boot-parent/pom.xml | 2 +- spring-boot-parent/src/checkstyle/checkstyle.xml | 1 + .../boot/loader/data/RandomAccessDataFile.java | 8 ++++---- .../org/springframework/boot/loader/jar/Handler.java | 10 +++++----- .../boot/context/embedded/tomcat/TomcatErrorPage.java | 10 ++++------ 11 files changed, 30 insertions(+), 26 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index d6b304eb8e..538ac5c0a4 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -69,7 +69,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @Import(DataSourceInitializedPublisher.Registrar.class) public abstract class JpaBaseConfiguration implements BeanFactoryAware { - private final Log logger = LogFactory.getLog(getClass()); + private static final Log logger = LogFactory.getLog(JpaBaseConfiguration.class); private final DataSource dataSource; @@ -197,8 +197,8 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { return ResourceUtils.extractJarFileURL(url); } catch (Exception ex) { - logger.info("Could not determine persistence " - + "unit root location from " + source + " : " + ex); + logger.info("Could not determine persistence " + "unit root location from " + + source + " : " + ex); } return null; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/AbstractTemplateResolverConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/AbstractTemplateResolverConfiguration.java index 91c40a1156..aabe21f985 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/AbstractTemplateResolverConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/AbstractTemplateResolverConfiguration.java @@ -37,7 +37,7 @@ abstract class AbstractTemplateResolverConfiguration { private static final Log logger = LogFactory .getLog(AbstractTemplateResolverConfiguration.class); - protected final ThymeleafProperties properties; + private final ThymeleafProperties properties; private final ApplicationContext applicationContext; @@ -47,6 +47,10 @@ abstract class AbstractTemplateResolverConfiguration { this.applicationContext = applicationContext; } + protected final ThymeleafProperties getProperties() { + return this.properties; + } + @PostConstruct public void checkTemplateLocationExists() { boolean checkTemplateLocation = this.properties.isCheckTemplateLocation(); diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java index a7cdd995a5..064840d6e3 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafAutoConfiguration.java @@ -137,9 +137,10 @@ public class ThymeleafAutoConfiguration { @Override public SpringResourceTemplateResolver defaultTemplateResolver() { SpringResourceTemplateResolver resolver = super.defaultTemplateResolver(); - Method setCheckExistence = ReflectionUtils - .findMethod(resolver.getClass(), "setCheckExistence", boolean.class); - ReflectionUtils.invokeMethod(setCheckExistence, resolver, this.properties.isCheckTemplate()); + Method setCheckExistence = ReflectionUtils.findMethod(resolver.getClass(), + "setCheckExistence", boolean.class); + ReflectionUtils.invokeMethod(setCheckExistence, resolver, + getProperties().isCheckTemplate()); return resolver; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java index eb8e3687cb..e9c14c3a19 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java @@ -109,7 +109,7 @@ public class ThymeleafProperties { } public boolean isCheckTemplate() { - return checkTemplate; + return this.checkTemplate; } public void setCheckTemplate(boolean checkTemplate) { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java index 015ace3c5e..9a5d03faaa 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java @@ -68,7 +68,7 @@ public class MultipartAutoConfiguration { @ConditionalOnMissingBean(MultipartResolver.class) public StandardServletMultipartResolver multipartResolver() { StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver(); - multipartResolver.setResolveLazily(multipartProperties.isResolveLazily()); + multipartResolver.setResolveLazily(this.multipartProperties.isResolveLazily()); return multipartResolver; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java index 01ecc8cf36..315d6484fc 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartProperties.java @@ -123,7 +123,7 @@ public class MultipartProperties { } public boolean isResolveLazily() { - return resolveLazily; + return this.resolveLazily; } public void setResolveLazily(boolean resolveLazily) { diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index d2ae41253d..a903f15253 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -264,7 +264,7 @@ com.puppycrawl.tools checkstyle - 6.17 + 7.1.1 diff --git a/spring-boot-parent/src/checkstyle/checkstyle.xml b/spring-boot-parent/src/checkstyle/checkstyle.xml index 855d278b49..8bb9e0a83a 100644 --- a/spring-boot-parent/src/checkstyle/checkstyle.xml +++ b/spring-boot-parent/src/checkstyle/checkstyle.xml @@ -62,6 +62,7 @@ + diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java index 435685d41a..384107bdd6 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/data/RandomAccessDataFile.java @@ -260,10 +260,10 @@ public class RandomAccessDataFile implements RandomAccessData { public void close() throws IOException { this.available.acquireUninterruptibly(this.size); try { - RandomAccessFile file = this.files.poll(); - while (file != null) { - file.close(); - file = this.files.poll(); + RandomAccessFile pooledFile = this.files.poll(); + while (pooledFile != null) { + pooledFile.close(); + pooledFile = this.files.poll(); } } finally { diff --git a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java index bb28ba5970..4637c65a32 100644 --- a/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java +++ b/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/jar/Handler.java @@ -158,12 +158,12 @@ public class Handler extends URLStreamHandler { String path = name.substring(FILE_PROTOCOL.length()); File file = new File(URLDecoder.decode(path, "UTF-8")); Map cache = rootFileCache.get(); - JarFile jarFile = (cache == null ? null : cache.get(file)); - if (jarFile == null) { - jarFile = new JarFile(file); - addToRootFileCache(file, jarFile); + JarFile result = (cache == null ? null : cache.get(file)); + if (result == null) { + result = new JarFile(file); + addToRootFileCache(file, result); } - return jarFile; + return result; } catch (Exception ex) { throw new IOException("Unable to open root Jar file '" + name + "'", ex); diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java index 86ac295f1d..aec6a27877 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatErrorPage.java @@ -54,14 +54,12 @@ class TomcatErrorPage { } private Object createNativePage(ErrorPage errorPage) { - Object nativePage = null; try { if (ClassUtils.isPresent(ERROR_PAGE_CLASS, null)) { - nativePage = BeanUtils - .instantiate(ClassUtils.forName(ERROR_PAGE_CLASS, null)); + return BeanUtils.instantiate(ClassUtils.forName(ERROR_PAGE_CLASS, null)); } - else if (ClassUtils.isPresent(LEGACY_ERROR_PAGE_CLASS, null)) { - nativePage = BeanUtils + if (ClassUtils.isPresent(LEGACY_ERROR_PAGE_CLASS, null)) { + return BeanUtils .instantiate(ClassUtils.forName(LEGACY_ERROR_PAGE_CLASS, null)); } } @@ -71,7 +69,7 @@ class TomcatErrorPage { catch (LinkageError ex) { // Swallow and continue } - return nativePage; + return null; } public void addToContext(Context context) {