Bug 50700 - Context parameters are being overridden with parameters from the web application deployment descriptor
Summary: Context parameters are being overridden with parameters from the web applicat...
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.30
Hardware: PC All
: P2 normal with 7 votes (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
: 47516 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-02-01 13:04 UTC by Sergey
Modified: 2014-02-17 13:42 UTC (History)
4 users (show)



Attachments

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"/>
....
</Context>

lines from web.xml
    <context-param>
        <description>default value for parameter_name</description>
        <param-name>parameter_name</param-name>
        <param-value>test2</param-value>
    </context-param>

Now servletContext.getInitParameter("parameter_name") returns "test2"
Comment 1 apache 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"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">
  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
  <context-param>
    <param-name>initialDbPath</param-name>
	<param-value>a</param-value>
  </context-param>
</web-app>

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

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

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

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

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. ***