Bug 52474 - Do not load listeners declared with blank spaces on tld file.
Do not load listeners declared with blank spaces on tld file.
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
PC All
: P2 normal (vote)
: ---
Assigned To: Tomcat Developers Mailing List
Depends on:
  Show dependency tree
Reported: 2012-01-17 05:41 UTC by Helio Frota
Modified: 2012-01-21 02:30 UTC (History)
0 users

debugging tomcat source (222.26 KB, image/png)
2012-01-17 05:41 UTC, Helio Frota

Note You need to log in before you can comment on or make changes to this bug.
Description Helio Frota 2012-01-17 05:41:49 UTC
Created attachment 28163 [details]
debugging tomcat source

Do not load listeners declared with blank spaces on tld file.
Removing blank spaces the application run.
Comment 1 Helio Frota 2012-01-17 05:43:30 UTC
Comment on attachment 28163 [details]
debugging tomcat source

Image eclipse debugging attached.
Comment 2 Mark Thomas 2012-01-18 09:32:50 UTC
The error is in the TLD file, not how Tomcat handles it.
Comment 3 Helio Frota 2012-01-18 10:26:50 UTC
Hello Mark Thomas,

Servlet specification 2.5:


Rules for Processing the Deployment Descriptor

This section lists some general rules that Web containers and developers must note concerning the processing of the deployment descriptor for a Web application.

• Web containers must remove all leading and trailing whitespace, which is de-
fined as “S(white space)” in XML 1.0 (http://www.w3.org/TR/2000/WD-xml-
2e-20000814), for the element content of the text nodes of a deployment de-

JSP Specification:

Event Listeners
A tag library may include classes that are event listeners (see the Servlet 2.5
specification). The listeners classes are listed in the tag library descriptor and the JSP container automatically instantiates them and registers them. A Container is required to locate all TLD files (see Section JSP.7.3.1 for details on how they are identified), read their listener elements, and treat the event listeners as extensions of those listed in web.xml.
The order in which the listeners are registered is undefined, but they are
registered before application start.

So if the TLD file should be treated as an extension of the web.xml file, so the container should deal with the removal of any blank space right ?
Comment 4 Mark Thomas 2012-01-20 11:38:35 UTC
The text of the JSP specification doesn't include any details on how TLDs should be parsed. I can see where you are coming from with that chain of references but the meaning of those is that listeners defined in TLDs are equivalent to listeners defined in web.xml.

There is, however, a definitive answer if one looks at the Java EE XSDs.
Listeners in TLDs are of type javaee:listenerType
javaee:listenerType contains a listener-class of type javaee:fully-qualified-classType
javaee:fully-qualified-classType has a base type of javaee:string
The definition of javaee:string requires that leading and trailing white space is removed.

Therefore, the correct behaviour is to remove the leading and trailing white space. It looks like this may affect many more elements than just the listeners.
Comment 5 Helio Frota 2012-01-20 12:25:57 UTC
On org.apache.catalina.core.StandardContext class line 4701 what is the impact of adding a call to trim() ?

try {
    results[i] = instanceManager.newInstance(listeners[i]);

try {
    results[i] = instanceManager.newInstance(listeners[i].trim());
Comment 6 Mark Thomas 2012-01-20 21:21:07 UTC
That would work but I prefer fixing the problem at the source - during the parsing.

Normally, the digester trims white space, hence web.xml elements should be OK. Listeners in TLDs require special handling so the generic digester code that strips the white space isn't used. I have added a trim() to the listener handling code.

The fix has been made to trunk and 7.0.x and will be included in 7.0.26 onwards.
Comment 7 Helio Frota 2012-01-21 02:30:58 UTC
Thank you for your attention
The Java community thanks you.

Best regargs,
Helio Frota