From b94c7c6a1dc06eec7005caaa2c1899c17f31d9e7 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 28 Dec 2015 14:35:35 +0100 Subject: [PATCH] Guard instantiation of Tomcat's ErrorPage Closes gh-4839 --- .../TomcatEmbeddedServletContainerFactory.java | 18 ++++++++++-------- 1 file changed, 10 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 363f8b2aee..ecafc29460 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 @@ -599,6 +599,10 @@ public class TomcatEmbeddedServletContainerFactory private static class TomcatErrorPage { + private static final String ERROR_PAGE_TOMCAT7 = "org.apache.catalina.deploy.ErrorPage"; + + private static final String ERROR_PAGE_TOMCAT = "org.apache.tomcat.util.descriptor.web.ErrorPage"; + private final String location; private final String exceptionType; @@ -617,14 +621,13 @@ public class TomcatEmbeddedServletContainerFactory private Object createNativePage(ErrorPage errorPage) { Object nativePage = null; try { - if (ClassUtils.isPresent( - "org.apache.tomcat.util.descriptor.web.ErrorPage", null)) { - nativePage = new org.apache.tomcat.util.descriptor.web.ErrorPage(); + if (ClassUtils.isPresent(ERROR_PAGE_TOMCAT, null)) { + nativePage = BeanUtils.instantiate(ClassUtils + .forName(ERROR_PAGE_TOMCAT, null)); } - else if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage", - null)) { + else if (ClassUtils.isPresent(ERROR_PAGE_TOMCAT7, null)) { nativePage = BeanUtils.instantiate(ClassUtils - .forName("org.apache.catalina.deploy.ErrorPage", null)); + .forName(ERROR_PAGE_TOMCAT7, null)); } } catch (ClassNotFoundException ex) { @@ -639,8 +642,7 @@ public class TomcatEmbeddedServletContainerFactory public void addToContext(Context context) { Assert.state(this.nativePage != null, "Neither Tomcat 7 nor 8 detected so no native error page exists"); - if (ClassUtils.isPresent("org.apache.tomcat.util.descriptor.web.ErrorPage", - null)) { + if (ClassUtils.isPresent(ERROR_PAGE_TOMCAT, null)) { org.apache.tomcat.util.descriptor.web.ErrorPage errorPage = (org.apache.tomcat.util.descriptor.web.ErrorPage) this.nativePage; errorPage.setLocation(this.location); errorPage.setErrorCode(this.errorCode);