Bug 49351 - Tomcat Embedded fails if StandardService is not set
Summary: Tomcat Embedded fails if StandardService is not set
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.26
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2010-05-27 06:39 UTC by Martin Goldhahn
Modified: 2010-06-29 07:40 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Martin Goldhahn 2010-05-27 06:39:35 UTC
The code in StandardEngine (around line 354) handles the situation when the standard engine is not set. But if you don't do it, the execution of Tomcat embedded fails with a NPE. The reason for this is a missing name for the StandardService.

A workaround is to just add the StandardService to the server container with the following code:

    StandardService service = new StandardService();
    service.setContainer( server.getContainer() );

However, the name should be set in org.apache.catalina.core.StandardEngine:355 to the engine name.

The error exists in the trunk too.
Comment 1 Mark Thomas 2010-06-26 08:44:45 UTC
Trunk has been re-factored so that code doesn't exist any more.

The following patch should work for 6.0.x:

Index: java/org/apache/catalina/core/StandardEngine.java
--- java/org/apache/catalina/core/StandardEngine.java	(revision 958198)
+++ java/org/apache/catalina/core/StandardEngine.java	(working copy)
@@ -354,6 +354,8 @@
                 service=new StandardService();
                 service.setContainer( this );
+                // Use same name for Service
+                service.setName(getName());
             } catch( Throwable t ) {
Comment 2 Mark Thomas 2010-06-29 07:40:37 UTC
Fixed in 6.0.x and will be included in 6.0.28 onwards.