Skip to content

Commit b94c7c6

Browse files
committed
Guard instantiation of Tomcat's ErrorPage
Closes spring-projectsgh-4839
1 parent 12cefd2 commit b94c7c6

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/tomcat/TomcatEmbeddedServletContainerFactory.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,10 @@ public String getUriEncoding() {
599599

600600
private static class TomcatErrorPage {
601601

602+
private static final String ERROR_PAGE_TOMCAT7 = "org.apache.catalina.deploy.ErrorPage";
603+
604+
private static final String ERROR_PAGE_TOMCAT = "org.apache.tomcat.util.descriptor.web.ErrorPage";
605+
602606
private final String location;
603607

604608
private final String exceptionType;
@@ -617,14 +621,13 @@ public TomcatErrorPage(ErrorPage errorPage) {
617621
private Object createNativePage(ErrorPage errorPage) {
618622
Object nativePage = null;
619623
try {
620-
if (ClassUtils.isPresent(
621-
"org.apache.tomcat.util.descriptor.web.ErrorPage", null)) {
622-
nativePage = new org.apache.tomcat.util.descriptor.web.ErrorPage();
624+
if (ClassUtils.isPresent(ERROR_PAGE_TOMCAT, null)) {
625+
nativePage = BeanUtils.instantiate(ClassUtils
626+
.forName(ERROR_PAGE_TOMCAT, null));
623627
}
624-
else if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage",
625-
null)) {
628+
else if (ClassUtils.isPresent(ERROR_PAGE_TOMCAT7, null)) {
626629
nativePage = BeanUtils.instantiate(ClassUtils
627-
.forName("org.apache.catalina.deploy.ErrorPage", null));
630+
.forName(ERROR_PAGE_TOMCAT7, null));
628631
}
629632
}
630633
catch (ClassNotFoundException ex) {
@@ -639,8 +642,7 @@ else if (ClassUtils.isPresent("org.apache.catalina.deploy.ErrorPage",
639642
public void addToContext(Context context) {
640643
Assert.state(this.nativePage != null,
641644
"Neither Tomcat 7 nor 8 detected so no native error page exists");
642-
if (ClassUtils.isPresent("org.apache.tomcat.util.descriptor.web.ErrorPage",
643-
null)) {
645+
if (ClassUtils.isPresent(ERROR_PAGE_TOMCAT, null)) {
644646
org.apache.tomcat.util.descriptor.web.ErrorPage errorPage = (org.apache.tomcat.util.descriptor.web.ErrorPage) this.nativePage;
645647
errorPage.setLocation(this.location);
646648
errorPage.setErrorCode(this.errorCode);

0 commit comments

Comments
 (0)