Bug 50700 - Context parameters are being overridden with parameters from the web application deployment descriptor
Context parameters are being overridden with parameters from the web applicat...
Product: Tomcat 6
Classification: Unclassified
Component: Catalina
PC All
: P2 normal with 7 votes (vote)
: default
Assigned To: Tomcat Developers Mailing List
: 47516 (view as bug list)
Depends on:
  Show dependency tree
Reported: 2011-02-01 13:04 UTC by Sergey
Modified: 2014-02-17 13:42 UTC (History)
4 users (show)


Note You need to log in before you can comment on or make changes to this bug.
Description Sergey 2011-02-01 13:04:17 UTC
Context parameters are being overridden with parameters from the web application deployment descriptor even through "override" attribute is set to "false"

For example:
lines from context file
<Context path="/path" docBase="/path/to/docbase" cookies="true">
    <Parameter name="parameter_name" value="test1" override="false"/>

lines from web.xml
        <description>default value for parameter_name</description>

Now servletContext.getInitParameter("parameter_name") returns "test2"
Comment 1 Oliver Doepner 2011-02-04 13:52:27 UTC
I can reproduce the problem (Tomcat 6.0.30 on JDK6u23, Windows XP, 32bit, *.zip distribution).
Comment 2 chris 2011-02-07 11:22:09 UTC
can reproduce using apache-tomcat-7.0.8-windows-x86.zip, jdk1.6.0_23, windows 7
Comment 3 chris 2011-02-08 04:12:56 UTC
Sergey's explanation is good, but just in case any more detail is required in how to reproduce it, here's the steps I take. Expand a tomcat distribution. Edit the <tomcat_home>\webapps\root\WEB-INF\web.xml file to become

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  <display-name>Welcome to Tomcat</display-name>
     Welcome to Tomcat

then edit <tomcat_home>\conf\context.xml to become

	<Parameter name="initialDbPath" value="xyz" override="false"/>

then add a new file <tomcat_home>\webapps\ROOT\test.jsp which contains

<%@ page contentType="text/html; charset=UTF-8" %>
<br>initialDbPath is : ${initParam.initialDbPath}

The context.xml setting should override the web.xml setting, but this is not happening
Comment 4 Mark Thomas 2011-02-14 14:06:02 UTC
This has been fixed in 7.0.x and will be included in 7.0.9 onwards.
Comment 5 Mark Thomas 2011-02-14 14:09:10 UTC
The Tomcat 7 patch has been proposed for backport to 6.0.x.
Comment 6 Konstantin Kolinko 2011-02-15 02:48:13 UTC
Some comments on the fix for this issue (r1070609), for better understanding:

1) This bug was caused by the fix for bug 49987 (r1022117), Tomcat 6.0.30-32 are affected.
2) The cause of this, which went unnoticed when the patch for Bug 49987 was reviewed, is that ApplicationContext#setInitParameter(name, value) is effective only once.

Subsequent calls to #setInitParameter(name, value) with the same name are ignored. That is why init-param overriding with override="false" stopped working.
Comment 7 Mark Thomas 2011-03-10 08:52:53 UTC
Fixed in 6.0.x and will be included in 6.0.33 onwards.
Comment 8 Konstantin Kolinko 2011-07-13 12:35:10 UTC
*** Bug 47516 has been marked as a duplicate of this bug. ***