Bug 30149 - IllegalArgumentException when using context-param in web.xml
Summary: IllegalArgumentException when using context-param in web.xml
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Catalina (show other bugs)
Version: Nightly Build
Hardware: All All
: P3 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-16 12:53 UTC by Cheng Fang
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cheng Fang 2004-07-16 12:53:45 UTC
It appears any wars with context-param failed to
deploy.  When parsing web.xml, context-param elements are parsed and added
to map twice for some reason, and thus cause the second adding to throw
IllegalArgumentException.

I instrumented
apache/jakarta-tomcat-
catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java
addParameter method

Here it shows context-param was added twice:

INFO: Installing web application at context path /jsp-examples from URL
file:/.../jakarta-tomcat-5/webapps/jsp-examples
### name=webmaster value=myaddress@mycompany.com
### map={}
### value=null
### to add ok
### name=webmaster value=myaddress@mycompany.com
### map={webmaster=myaddress@mycompany.com}
### value=myaddress@mycompany.com
### to throw

To repruduce it, just add to jsp-examples/web-inf/web.xml:

    <context-param>
      <param-name>webmaster</param-name>
      <param-value>myaddress@mycompany.com</param-value>
      <description>
        The EMAIL address of the administrator to whom questions
        and comments about this application should be addressed.
      </description>
    </context-param>

Stack trace from catalina.log:
Jul 15, 2004 9:54:37 PM org.apache.tomcat.util.digester.Digester endElement
SEVERE: End event threw exception
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at org.apache.tomcat.util.IntrospectionUtils.callMethodN
(IntrospectionUtils.java:907)
        at org.apache.tomcat.util.digester.CallMethodRule.end
(CallMethodRule.java:576)
        at org.apache.tomcat.util.digester.Rule.end(Rule.java:228)
        at org.apache.tomcat.util.digester.Digester.endElement
(Digester.java:1057)
        at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1720)
        at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
        at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
        at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
        at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
        at org.apache.catalina.startup.ContextConfig.applicationConfig
(ContextConfig.java:234)
        at org.apache.catalina.startup.ContextConfig.start
(ContextConfig.java:557)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent
(ContextConfig.java:187)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent
(LifecycleSupport.java:119)
        at org.apache.catalina.core.StandardContext.start
(StandardContext.java:4285)
        at org.apache.catalina.core.ContainerBase.addChildInternal
(ContainerBase.java:755)
        at org.apache.catalina.core.ContainerBase.addChild
(ContainerBase.java:739)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
        at org.apache.catalina.core.StandardHostDeployer.install
(StandardHostDeployer.java:276)
        at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
        at org.apache.catalina.startup.HostConfig.deployWARs
(HostConfig.java:584)
        at org.apache.catalina.startup.HostConfig.deployApps
(HostConfig.java:398)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:997)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent
(HostConfig.java:298)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent
(LifecycleSupport.java:119)
        at org.apache.catalina.core.StandardHost.backgroundProcess
(StandardHost.java:800)
        at 
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChild
ren(ContainerBase.java:1511)
        at 
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChild
ren(ContainerBase.java:1520)
        at 
org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run
(ContainerBase.java:1500)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalArgumentException: Duplicate context initialization 
parameter webmaster
        at org.apache.catalina.core.StandardContext.addParameter
(StandardContext.java:2116)
        ... 35 more
Jul 15, 2004 9:54:37 PM org.apache.catalina.startup.ContextConfig 
applicationConfig
SEVERE: Parse error in application web.xml
java.lang.IllegalArgumentException: Duplicate context initialization parameter 
webmaster
        at org.apache.tomcat.util.digester.Digester.createSAXException
(Digester.java:2740)
        at org.apache.tomcat.util.digester.Digester.createSAXException
(Digester.java:2766)
        at org.apache.tomcat.util.digester.Digester.endElement
(Digester.java:1060)
        at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1720)
Comment 1 Cheng Fang 2004-07-22 19:39:06 UTC
I traced the problem to CallMethodRule class, where callMethodN was invoked 
twice.  With the following change, Tomcat works fine with context-param.  I 
also tested this change with jsp tck.  I will appreciate it if someone could 
review and apply it.

Index: CallMethodRule.java
===================================================================
RCS file: /home/cvspublic/jakarta-tomcat-
connectors/util/java/org/apache/tomcat/util/digester/CallMethodRule.java,v
retrieving revision 1.1
diff -u -r1.1 CallMethodRule.java
--- CallMethodRule.java 26 Jun 2004 17:41:30 -0000      1.1
+++ CallMethodRule.java 22 Jul 2004 19:24:05 -0000
@@ -572,7 +572,6 @@
             sb.append(")");
             digester.log.debug(sb.toString());
         }
-        IntrospectionUtils.callMethodN(target, methodName, paramValues, 
paramTypes);
         Object result = IntrospectionUtils.callMethodN(target, methodName,
                 paramValues, paramTypes);
         processMethodCallResult(result);
Comment 2 Jan Luehe 2004-07-23 15:59:36 UTC
Fixed by applying Cheng's patch.