From 0fdd7e18431170e2415dbdbec89a7b7e1ed8b6c6 Mon Sep 17 00:00:00 2001 From: bstick12 Date: Tue, 28 Jan 2014 17:39:55 +0000 Subject: [PATCH] Fix TomcatContextCustomizers Assert.notNull checks Correct null assertion checks on setters for TomcatContextCustomizers and TomcatContextCustomizers --- ...TomcatEmbeddedServletContainerFactory.java | 14 ++++---- ...tEmbeddedServletContainerFactoryTests.java | 34 ++++++++++++++++++- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java index 03da368ccb..ae98e27eaf 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java @@ -371,7 +371,7 @@ public class TomcatEmbeddedServletContainerFactory extends */ public void setTomcatContextCustomizers( Collection tomcatContextCustomizers) { - Assert.notNull(this.contextLifecycleListeners, + Assert.notNull(tomcatContextCustomizers, "TomcatContextCustomizers must not be null"); this.tomcatContextCustomizers = new ArrayList( tomcatContextCustomizers); @@ -392,8 +392,8 @@ public class TomcatEmbeddedServletContainerFactory extends * @param tomcatContextCustomizers the customizers to add */ public void addContextCustomizers(TomcatContextCustomizer... tomcatContextCustomizers) { - Assert.notNull(this.tomcatContextCustomizers, - "TomcatContextCustomizer must not be null"); + Assert.notNull(tomcatContextCustomizers, + "TomcatContextCustomizers must not be null"); this.tomcatContextCustomizers.addAll(Arrays.asList(tomcatContextCustomizers)); } @@ -404,8 +404,8 @@ public class TomcatEmbeddedServletContainerFactory extends */ public void setTomcatConnectorCustomizers( Collection tomcatConnectorCustomizers) { - Assert.notNull(this.contextLifecycleListeners, - "TomcatConnectorCustomizer must not be null"); + Assert.notNull(tomcatConnectorCustomizers, + "TomcatConnectorCustomizers must not be null"); this.tomcatConnectorCustomizers = new ArrayList( tomcatConnectorCustomizers); } @@ -417,8 +417,8 @@ public class TomcatEmbeddedServletContainerFactory extends */ public void addConnectorCustomizers( TomcatConnectorCustomizer... tomcatConnectorCustomizers) { - Assert.notNull(this.tomcatContextCustomizers, - "TomcatConnectorCustomizer must not be null"); + Assert.notNull(tomcatConnectorCustomizers, + "TomcatConnectorCustomizers must not be null"); this.tomcatConnectorCustomizers.addAll(Arrays.asList(tomcatConnectorCustomizers)); } diff --git a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java b/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java index cd1f5a9af1..221badea97 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 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. @@ -138,6 +138,38 @@ public class TomcatEmbeddedServletContainerFactoryTests extends verify(valve).setNext(any(Valve.class)); } + @Test + public void setNullTomcatContextCustomizersThrows() { + TomcatEmbeddedServletContainerFactory factory = getFactory(); + this.thrown.expect(IllegalArgumentException.class); + this.thrown.expectMessage("TomcatContextCustomizers must not be null"); + factory.setTomcatContextCustomizers(null); + } + + @Test + public void addNullContextCustomizersThrows() { + TomcatEmbeddedServletContainerFactory factory = getFactory(); + this.thrown.expect(IllegalArgumentException.class); + this.thrown.expectMessage("TomcatContextCustomizers must not be null"); + factory.addContextCustomizers((TomcatContextCustomizer[]) null); + } + + @Test + public void setNullTomcatConnectorCustomizersThrows() { + TomcatEmbeddedServletContainerFactory factory = getFactory(); + this.thrown.expect(IllegalArgumentException.class); + this.thrown.expectMessage("TomcatConnectorCustomizers must not be null"); + factory.setTomcatConnectorCustomizers(null); + } + + @Test + public void addNullConnectorCustomizersThrows() { + TomcatEmbeddedServletContainerFactory factory = getFactory(); + this.thrown.expect(IllegalArgumentException.class); + this.thrown.expectMessage("TomcatConnectorCustomizers must not be null"); + factory.addConnectorCustomizers((TomcatConnectorCustomizer[]) null); + } + private void assertTimeout(TomcatEmbeddedServletContainerFactory factory, int expected) { this.container = factory.getEmbeddedServletContainer(); Tomcat tomcat = ((TomcatEmbeddedServletContainer) this.container).getTomcat();