Bug 47462

Summary: The annotation doesn't become effective.(metadata-complete="false" is not effective.)
Product: Tomcat 6 Reporter: Keiichi Fujino <fujino.keiichi>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: charly41434
Priority: P2    
Version: 6.0.20   
Target Milestone: default   
Hardware: PC   
OS: Windows XP   
Attachments: new patch.

Description Keiichi Fujino 2009-07-01 02:51:39 UTC
Even if "false" is set to metadata-complete, 
the annotation doesn't become effective. 

To invalidate the annotation by all the Web applications of Tomcat, 
metadata-complete of conf/web.xml is set to "true". 

[conf/web.xml]
<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"
    metadata-complete="true"
    >
.....
</web-app>

To make the annotation of Web application (testWebApp) effective, 
metadata-complete of webapps/testWebApp/WEB-INF/web.xml is set to "false".

[webapps/testWebApp/WEB-INF/web.xml]
<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"
   metadata-complete="false"> 
....
</web-app>

However, testWebApp doesn't make the annotation effective. 

Because WebRuleSet#IgnoreAnnotationsRule#begin is as follows. 
When metadata-complete is "false", context.setIgnoreAnnotations(false) is not invoked. 
[WebRuleSet#IgnoreAnnotationsRule#begin]
final class IgnoreAnnotationsRule extends Rule {

    public IgnoreAnnotationsRule() {
    }

    public void begin(String namespace, String name, Attributes attributes)
        throws Exception {
        Context context = (Context) digester.peek(digester.getCount() - 1);
        String value = attributes.getValue("metadata-complete");
        if ("true".equals(value)) {
            context.setIgnoreAnnotations(true);
        }
        if (digester.getLogger().isDebugEnabled()) {
            digester.getLogger().debug
                (context.getClass().getName() + ".setIgnoreAnnotations( " +
                    context.getIgnoreAnnotations() + ")");
        }
    }

}

I think that the following patches are necessary. 

Index: java/org/apache/catalina/startup/WebRuleSet.java
===================================================================
--- java/org/apache/catalina/startup/WebRuleSet.java	(revision 763870)
+++ java/org/apache/catalina/startup/WebRuleSet.java	(working copy)
@@ -848,6 +848,8 @@
         String value = attributes.getValue("metadata-complete");
         if ("true".equals(value)) {
             context.setIgnoreAnnotations(true);
+        } else if ("false".equals(value)) {
+            context.setIgnoreAnnotations(false);
         }
         if (digester.getLogger().isDebugEnabled()) {
             digester.getLogger().debug


Best regards.
Comment 1 Mark Thomas 2009-11-22 12:52:02 UTC
Thanks for the patch. It has been applied to trunk and proposed for 5.5.x and 6.0.x
Comment 2 Konstantin Kolinko 2009-12-16 23:45:57 UTC
SRV.14.5 of Servlet 2.5 says that if “metadata-complete” attribute is absent, it must be treated the same way as having the value of "false".

Thus, if we allow to specify it in global conf/web.xml, setting it to "true" there will result in violation of the spec.
Comment 3 Keiichi Fujino 2009-12-17 02:08:29 UTC
Created attachment 24721 [details]
new patch.

Oops!
My patch was a mistake. 
However, even if this patch is reverted, it is a violation of spec yet. 

If “metadata-complete" of conf/web.xml is set true, 
and “metadata-complete" is not specified in each webApp, 
the annotation is invalid yet. 

This is violation of spec.

I made a new patch. 
if“metadata-complete" is not specified, the annotation is made effective.
Comment 4 Mark Thomas 2009-12-17 08:16:39 UTC
(In reply to comment #2)
> SRV.14.5 of Servlet 2.5 says that if “metadata-complete” attribute is absent,
> it must be treated the same way as having the value of "false".
> 
> Thus, if we allow to specify it in global conf/web.xml, setting it to "true"
> there will result in violation of the spec.

I disagree. The spec does not consider the concept of a global or default web.xml. A global web.xml is a Tomcat invention and one where Tomcat controls how it is to be interpreted, not the spec. The convention is the the global web.xml sets the defaults for all application web.xml files unless explicitly overridden at the application level. Hence the behaviour with the patch applied is as expected.
Comment 5 Mark Thomas 2009-12-17 08:17:37 UTC
(In reply to comment #3)
> Created an attachment (id=24721) [details]
> new patch.

I can't see why null needs to be handled here. The only acceptable values are true or false.
Comment 6 Konstantin Kolinko 2009-12-17 12:21:14 UTC
From second thought:
- The spec authors had to specify how to interpret the missing value. Leaving that unspecified would be much worse.
- The default content of global conf/web.xml provides specification-compliant behavior. If you start changing that file, you should know what you are doing.

Thus, let's go with the original patch.
Comment 7 Keiichi Fujino 2009-12-17 16:42:58 UTC
(In reply to comment #5)
> (In reply to comment #3)
> > Created an attachment (id=24721) [details] [details]
> > new patch.
> 
> I can't see why null needs to be handled here. The only acceptable values are
> true or false.

I think.
f "metadata-complete" is not specified for web.xml, value becomes null. 
In a new patch.
For a strict spec, if "metadata-complete" is not specified, the annotation was made effective. 
However, I think that the concept is more profitable of conf/web.xml as for the comment 4. 

I support the previous patch. 

many thanks.
Comment 8 Mark Thomas 2009-12-19 14:35:59 UTC
The patch has been applied to 6.0.x and will be included in 6.0.21 onwards.
Comment 9 Konstantin Kolinko 2010-01-06 18:06:55 UTC
metadata-complete is @since Servlet 2.5,
so this issue is not applicable to Tomcat 5.5.
Closing as FIXED in TC 6.