From f57f16c1902ffe4834e115c662df9eabc3e4ec07 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Mon, 19 Nov 2018 14:09:28 +0100 Subject: [PATCH] Avoid premature declaration of variables Closes gh-15215 --- .../servlet/CloudFoundryWebEndpointServletHandlerMapping.java | 4 ++-- .../actuate/autoconfigure/web/server/ManagementPortType.java | 2 +- .../autoconfigure/properties/AnnotationsPropertySource.java | 2 +- .../boot/context/properties/bind/BindConverter.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java index 430ce78e06..edca94df18 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundryWebEndpointServletHandlerMapping.java @@ -91,12 +91,12 @@ class CloudFoundryWebEndpointServletHandlerMapping } AccessLevel accessLevel = (AccessLevel) request .getAttribute(AccessLevel.REQUEST_ATTRIBUTE); - Map links = CloudFoundryWebEndpointServletHandlerMapping.this.linksResolver - .resolveLinks(request.getRequestURL().toString()); Map filteredLinks = new LinkedHashMap<>(); if (accessLevel == null) { return Collections.singletonMap("_links", filteredLinks); } + Map links = CloudFoundryWebEndpointServletHandlerMapping.this.linksResolver + .resolveLinks(request.getRequestURL().toString()); filteredLinks = links.entrySet().stream() .filter((e) -> e.getKey().equals("self") || accessLevel.isAccessAllowed(e.getKey())) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementPortType.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementPortType.java index eccc7b59e1..7e9d2f9381 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementPortType.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementPortType.java @@ -42,11 +42,11 @@ public enum ManagementPortType { DIFFERENT; static ManagementPortType get(Environment environment) { - Integer serverPort = getPortProperty(environment, "server."); Integer managementPort = getPortProperty(environment, "management.server."); if (managementPort != null && managementPort < 0) { return DISABLED; } + Integer serverPort = getPortProperty(environment, "server."); return ((managementPort == null || (serverPort == null && managementPort.equals(8080)) || (managementPort != 0 && managementPort.equals(serverPort))) ? SAME diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java index c28af2b6bb..59459b0047 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java @@ -120,7 +120,6 @@ public class AnnotationsPropertySource extends EnumerablePropertySource if (skip == SkipPropertyMapping.YES) { return; } - String name = getName(typeMapping, attributeMapping, attribute); ReflectionUtils.makeAccessible(attribute); Object value = ReflectionUtils.invokeMethod(attribute, annotation); if (skip == SkipPropertyMapping.ON_DEFAULT_VALUE) { @@ -130,6 +129,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource return; } } + String name = getName(typeMapping, attributeMapping, attribute); putProperties(name, value, properties); } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java index b292e2bd09..9f4fced933 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/BindConverter.java @@ -242,12 +242,12 @@ final class BindConverter { } private PropertyEditor getPropertyEditor(Class type) { - SimpleTypeConverter typeConverter = this.typeConverter; if (type == null || type == Object.class || Collection.class.isAssignableFrom(type) || Map.class.isAssignableFrom(type)) { return null; } + SimpleTypeConverter typeConverter = this.typeConverter; PropertyEditor editor = typeConverter.getDefaultEditor(type); if (editor == null) { editor = typeConverter.findCustomEditor(type, null);