diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointServlet.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointServlet.java index 1731d6cb8c..44239b2fde 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointServlet.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/web/EndpointServlet.java @@ -61,9 +61,9 @@ public final class EndpointServlet { public EndpointServlet withInitParameters(Map initParameters) { Assert.notNull(initParameters, "InitParameters must not be null"); - boolean hasEmptyKey = initParameters.values().stream() - .anyMatch((key) -> !StringUtils.hasText(key)); - Assert.isTrue(!hasEmptyKey, "InitParameters must not contain empty keys"); + boolean hasEmptyName = initParameters.keySet().stream() + .anyMatch((name) -> !StringUtils.hasText(name)); + Assert.isTrue(!hasEmptyName, "InitParameters must not contain empty names"); Map mergedInitParameters = new LinkedHashMap<>( this.initParameters); mergedInitParameters.putAll(initParameters); diff --git a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/EndpointServletTests.java b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/EndpointServletTests.java index ee26b811fd..77a65d62d0 100644 --- a/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/EndpointServletTests.java +++ b/spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/EndpointServletTests.java @@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.entry; * Tests for {@link EndpointServlet}. * * @author Phillip Webb + * @author Stephane Nicoll */ public class EndpointServletTests { @@ -71,6 +72,20 @@ public class EndpointServletTests { assertThat(endpointServlet.getServlet()).isEqualTo(servlet); } + @Test + public void withInitParameterNullName() { + EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class); + this.thrown.expect(IllegalArgumentException.class); + endpointServlet.withInitParameters(Collections.singletonMap(null, "value")); + } + + @Test + public void withInitParameterEmptyName() { + EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class); + this.thrown.expect(IllegalArgumentException.class); + endpointServlet.withInitParameters(Collections.singletonMap(" ", "value")); + } + @Test public void withInitParameterShouldReturnNewInstance() { EndpointServlet endpointServlet = new EndpointServlet(TestServlet.class);