Bug 32719 - IntrospectionUtils feature causes $ charters to be stripped out of web.xml files
Summary: IntrospectionUtils feature causes $ charters to be stripped out of web.xml files
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Unknown (show other bugs)
Version: 5.5.4
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords: PatchAvailable
: 32577 34843 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-15 18:44 UTC by Richard Clark
Modified: 2005-11-24 08:26 UTC (History)
2 users (show)



Attachments
patch fixing this problem (978 bytes, patch)
2004-12-15 19:03 UTC, Richard Clark
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Clark 2004-12-15 18:44:11 UTC
class: org.apache.tomcat.util.IntrospectionUtils
method: replaceProperties(String, Hashtable, PropertySource[])
CVS:
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/IntrospectionUtils.java


A possibily unintentional feature of IntrospectionUtils.replaceProperties causes
the $ character to the stripped from web.xml files when they are loaded. 

This was discovered when the name of an inner class was specified as a parameter:

<init-param>
 <param-name>source.factory</param-name>
 <param-value>com.ssl.javaservlets.tihinterface.PcoRegionsSqlDataSource$Factory</param-value>
</init-param>

However when the servlet retrieved this parameter, the $ character had been
removed yeilding the result:
"com.ssl.javaservlets.tihinterface.PcoRegionsSqlDataSourceFactory"
rather than:
"com.ssl.javaservlets.tihinterface.PcoRegionsSqlDataSource$Factory"

This seemed related to the processing of replacement properties defined in the
style ${property.name}. However if the is no property "property.name" then the
raw text "${property.name}" passes through untouched, likewise if a $ is placed
a the end of a string.

Upon inspecting the IntrospectionUtils.replaceProperties method, I noticed that
this behaviour was due to the following code starting @ line 475:

} else if (value.charAt(pos + 1) != '{') {
    sb.append(value.charAt(pos + 1));
    prev = pos + 2; // XXX
} else {

Therefore after consuming a $ and the lookahead says that a non { character
follows, only the non { character is placed on the buffer and the $ which has
just been consumed is dropped. This can be fixed by simply adding the $ to the
buffer, thus:

} else if (value.charAt(pos + 1) != '{') {
    sb.append('$');
    sb.append(value.charAt(pos + 1));
    prev = pos + 2; 
} else {


I looking back over the CVS history this faulty logic is almost 3 years old, yet
I could not find an entry in the bug database for it. I've been using Tomcat for
over 3 years now myself and find it strange to of only stubled over this bug
after all this time, I guess I've never used a string with the $ character before :P
Comment 1 Richard Clark 2004-12-15 19:03:31 UTC
Created attachment 13761 [details]
patch fixing this problem

Added patch
Comment 2 Ben Souther 2004-12-16 03:26:55 UTC
*** Bug 32577 has been marked as a duplicate of this bug. ***
Comment 3 william.barker 2004-12-16 04:54:57 UTC
This is fixed in the CVS.  The fix is modified from the patch here, since your 
patch doesn't handle the case:
   <listener-class>package.MyClass$${inner.class}</listener-class>

 

Comment 4 Steve Loughran 2005-11-24 17:26:07 UTC
*** Bug 34843 has been marked as a duplicate of this bug. ***