Bug 53619

Summary: If <absolute-ordering> is defined, only fragments mentioned in it shall get class-scanned
Product: Tomcat 7 Reporter: Mark Struberg <struberg>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 7.0.29   
Target Milestone: ---   
Hardware: PC   
OS: All   

Description Mark Struberg 2012-07-30 07:44:33 UTC
There was a discussion at the dev list how one could prevent his app from scanning all the classpath if a ServletContextInitializer is found:


Mark pointed me at a current EG discussion: 

The agreed status seems to be that _if_ an <absolute-ordering> element exists in WEB-INF/web.xml, then only the web-fragments mentioned therein shall be scanned. This is especially true if the <absolute-ordering> contains no <others/> element.

An empty <absolute-ordering/> shall therefore disable scanning at all as far as I understood.

This seems already be reflected in servlet-3.0 section 8.2.2 "Ordering of web.xml and web-fragment.xml" paragraph 1.d:
"If a discovered ServletContainerInitializer is loaded from an excluded jar, it will be ignored. Excluded jars are not scanned for classes to be handled by any ServletContainerInitializer."

What I do not yet completely understand is that servlet-3.0 section 8.2.1 "Modularity of web.xml" explicitly defines as general rule:

"As before, if the metadata-complete element is set to true in the web.xml descriptor, annotations in the class files and web-fragments bundled in jars will not be processed."

This not only contradicts the 'clarification' of the EG regarding the ServletContextInitializer which is in question here, but also could be interpreted as : "if metadata-complete is true, then no web-fragment handling is done. Thus also no <absolute-ordering> will be evaluated".
Not that I would like this, I just like to have this clarified upfront (before we have to throw away some work afterwards).

Did I miss something in this regard?
Comment 1 Mark Struberg 2012-07-30 08:11:38 UTC
whoops s/ServletContextInitializer/ServletContainerInitializer/
Comment 2 Mark Thomas 2012-08-11 19:28:50 UTC
The required behaviour has been present from 7.0.29 onwards in anticipation of the clarification from the EG.
Comment 3 bmesserer 2013-01-08 13:34:11 UTC
Provided I understand Mark's comments correctly, the current behavior (tomcat 7.0.34) is incorrect regarding this:

"An empty <absolute-ordering/> shall therefore disable scanning at all as far as I understood."

It does not, an empty 'absolute-ordering' element has no effect whatsoever (regarding this bug). From short debugging, org.apache.catalina.deploy.WebXml.absoluteOrdering only contains the child elements of the tag (see WebXml#addAbsoluteOrdering*(...)).

Hope that somebody can clarify whether current behavior is wrong or abovementioned comment is, so won't change status of this.