Bug 53090 - Servlet superclass injection targets are ignored
Summary: Servlet superclass injection targets are ignored
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.26
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2012-04-17 08:07 UTC by Borislav Kapukaranov
Modified: 2012-05-29 17:26 UTC (History)
1 user (show)

patch that shows the processing of the servlet's superclass injections (1.49 KB, patch)
2012-04-17 08:07 UTC, Borislav Kapukaranov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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,
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

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.