Bug 51386 - @HandlingType not correctly handled at server startup leads to incorrect classes set passed to initializers
Summary: @HandlingType not correctly handled at server startup leads to incorrect clas...
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: trunk
Hardware: PC Windows XP
: P2 critical (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2011-06-16 14:12 UTC by Etienne Massip
Modified: 2011-06-16 17:24 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Etienne Massip 2011-06-16 14:12:27 UTC
The following code in org.apache.catalina.startup.ContextConfig.checkHandlesTypes(JavaClass) looks very buggy :

  boolean match = false;
  for (Map.Entry<Class<?>, Set<ServletContainerInitializer>> entry :
          typeInitializerMap.entrySet()) {
      if (entry.getKey().isAnnotation()) {
          AnnotationEntry[] annotationEntries = javaClass.getAnnotationEntries();
          for (AnnotationEntry annotationEntry : annotationEntries) {
              if (entry.getKey().getName().equals(
                  getClassName(annotationEntry.getAnnotationType()))) {
                  match = true;
      } else if (entry.getKey().isAssignableFrom(clazz)) {
          match = true;
      if (match) {
          for (ServletContainerInitializer sci : entry.getValue()) {

Shouldn't "match" variable be reset to false at each iteration ?

As it is for now, my SpringServletContainerInitializer (3.1M2), handling only WebApplicationInitializers, will finally receive a huge set of various applicative classes, starting from the first class parsed matching any type handled by any previously parsed ServletContainerInitializer !!!

Comment 1 Etienne Massip 2011-06-16 14:55:12 UTC
Finally leading to a cast exception preventing server startup.
Comment 2 Mark Thomas 2011-06-16 15:54:26 UTC
Yep, that looks like a problem. I'll put together a test case and fix.
Comment 3 Mark Thomas 2011-06-16 17:24:30 UTC
Thanks for the report. This has been fixed in 7.0.x and will be included in 7.0.17 onwards.