Bug 49351 - Tomcat Embedded fails if StandardService is not set
Summary: Tomcat Embedded fails if StandardService is not set
Status: RESOLVED FIXED
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
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-27 06:39 UTC by Martin Goldhahn
Modified: 2010-06-29 07:40 UTC (History)
0 users



Attachments

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:

<code>
    StandardService service = new StandardService();
    service.setContainer( server.getContainer() );
    service.setName(TC_HOST_CONTAINER_NAME);
    service.initialize();
</code>

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 );
                 service.initialize();
+                // Use same name for Service
+                service.setName(getName());
             } catch( Throwable t ) {
                 log.error(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.