Bug 53090

Summary: Servlet superclass injection targets are ignored
Product: Tomcat 7 Reporter: Borislav Kapukaranov <b.kapukaranov>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal CC: violetagg
Priority: P2    
Version: 7.0.26   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: patch that shows the processing of the servlet's superclass injections

Description Borislav Kapukaranov 2012-04-17 08:07:14 UTC
Created attachment 28623 [details]
patch that shows the processing of the servlet's superclass injections

Hi folks,

I've been running Tomcat 7.0.26 in a JEE container against the EE6 Web Profile CTS.
In many of the tests there is the following scenario: A servlet 'X' extends a regular class 'Y'. An env-entry element for a field in 'Y' with injection-target-class equal to 'Y' is defined in the app's web.xml. The injection-target-name points to a field that is not annotated.

When the app boots and Tomcat handles the injections for the servlet it processes only those that are defined explicitly for the 'X' servlet's class name, ignoring its superclasses.

I'm attaching a patch I made on top of 7.0.x/trunk that fixed the issue. It's quite small.

I believe Tomcat should respect the injections for the servlet's superclasses. What do you think is the right behavior?

Thank you,
Bobby
Comment 1 Mark Thomas 2012-05-28 21:23:34 UTC
Thanks for the patch. It has been applied to trunk and 7.0.x and will be included in 7.0.28 onwards.
Comment 2 Konstantin Kolinko 2012-05-28 23:22:03 UTC
Re r1343396 : I wonder whether interfaces should be scanned as well.

Can injection-target-class be an interface?
Comment 3 Violeta Georgieva 2012-05-29 17:26:55 UTC
Hi,

In the Java Platform EE 6 Spec, EE.5.2.5. Annotations and Injection, they specify that resource annotations may appear on any superclass of the class.

Annotations and inheritance topic is described also on the wiki http://java.net/projects/javaee-spec/pages/AnnotationRules

β€œIn general, annotations on interfaces are ignored.”

However there are specified also exceptions of the rule.

For our use case – resource annotations (@Resource, @EJB etc.) and injection target classes – I think that we should ignore them.

Regards
Violeta