Bug 49351

Summary: Tomcat Embedded fails if StandardService is not set
Product: Tomcat 6 Reporter: Martin Goldhahn <mgoldhahn>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 6.0.26   
Target Milestone: default   
Hardware: PC   
OS: Windows XP   

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.