Bug 47342 - ReplicatedContext#start throws NullPointerException.
ReplicatedContext#start throws NullPointerException.
Status: RESOLVED FIXED
Product: Tomcat 6
Classification: Unclassified
Component: Cluster
6.0.20
PC All
: P2 normal (vote)
: default
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2009-06-10 02:48 UTC by Keiichi Fujino
Modified: 2009-12-15 11:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Keiichi Fujino 2009-06-10 02:48:24 UTC
ReplicatedContext#start throws NullPointerException.

context.xml is as follows.
<Context className="org.apache.catalina.ha.context.ReplicatedContext" />

When Tomcat is started, the following logs are output. 

Jun 10, 2009 6:40:57 PM org.apache.catalina.ha.context.ReplicatedContext start
SEVERE: Unable to start ReplicatedContext
java.lang.NullPointerException
    at java.io.File.<init>(Unknown Source)
    at org.apache.catalina.core.StandardContext.getBasePath(StandardContext.java:4840)
    at org.apache.catalina.ha.context.ReplicatedContext.start(ReplicatedContext.java:63)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:526)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:630)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:556)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:491)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1206)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)


This causes because docBase has not been initialized. 
I think that this solution for the problem is an addition of initialization to ReplicatedContext#start. 

I made a patch.

Index: java/org/apache/catalina/ha/context/ReplicatedContext.java
===================================================================
--- java/org/apache/catalina/ha/context/ReplicatedContext.java    (revision 763870)
+++ java/org/apache/catalina/ha/context/ReplicatedContext.java    (working copy)
@@ -51,6 +51,13 @@
     @Override
     public synchronized void start() throws LifecycleException {
         if ( this.started ) return;
+        if( !initialized ) { 
+            try {
+                init();
+            } catch( Exception ex ) {
+                throw new LifecycleException("Error initializaing ", ex);
+            }
+        }
         super.addLifecycleListener(this);            
         try {
             CatalinaCluster catclust = (CatalinaCluster)this.getCluster();



Regards.
Comment 1 Filip Hanik 2009-06-18 11:16:14 UTC
I'm unable to replicate your use case, mostly cause it seems as the className attribute is ignored on the conf/context.xml element
Comment 2 Keiichi Fujino 2009-06-18 23:56:22 UTC
(In reply to comment #1)
> I'm unable to replicate your use case, mostly cause it seems as the className
> attribute is ignored on the conf/context.xml element

I'm so sorry in the insufficient explanation. 
To reproduce this bug
It is necessary to set ReplicatedContext to <<contextName>>.xml of conf/Catalina/localhost/directory. 
It is not conf/context.xml. 

IMHO,
I think that className attribute is ignored in conf/context.xml. 

Because
context instance is created by deployXXXX method of HostConfig.
and
The ContextRuleSet created by ContextConfig(parse conf/context.xml) is as follows. 
  RuleSet contextRuleSet = new ContextRuleSet("", false);
  
When boolean of the second argument is false, context instance is not created by Digester. 
As a Result, 
ObjectCreateRule to className attribute of Context is not added.
Comment 3 Mark Thomas 2009-11-30 16:39:23 UTC
Thanks for the patch.

The patch has been applied to trunk (although other changes in trunk mean the
NPE doesn't occur) and has been proposed for 6.0.x.
Comment 4 Mark Thomas 2009-12-15 11:05:46 UTC
The patch has been applied to 6.0.x and will be included in 6.0.21 onwards.

Again, many thanks for your work on this issue.