Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
8.0.12
-
None
-
Windows 10.0
Description
The behavior I'm describing was detected on a applications running on Tomee 8 (Apache Tomcat (TomEE)/9.0.63 (8.0.12)).
From my understanding and from what I observed Tomee proceeds in two main steps to support ServletContainerInitializer implementations :
- Instanciation of every ServletContainerInitializer implementations found,
- Call of the onStartup method for each ServletContainerInitializer.
From my point of view it is an issue when web fragments ordering has been configured because if a ServletContainerInitializer implementation class is loaded and instantiated it might trigger some static fields initialisation and static code execution. Therefore this code will be called before any of the onStartup method and break the configured order.
for (String serviceClass : servicesFound) { try { Class<?> clazz = Class.forName(serviceClass, true, loader); services.add(serviceType.cast(clazz.getConstructor().newInstance())); } catch (ReflectiveOperationException | ClassCastException e) { throw new IOException(e); } }
Example
For example log4j2-web contains the web-fragment below in order to make sure log4j is initialized before any other components that might attempt to log something:
<web-fragment ...> [...] <ordering> <before> <others /> </before> </ordering> </web-fragment>
But another library we use (Camunda) also contains it own ServletContainerInitializer implementation class with a static field, triggering static code, leading to log4j initialization before log4j's ServletContainerInitializer.onStartup method call.
And this is an issue because in that case log4j configuration relies on data from the ServletContext which has not been provided to log4j yet.
Expected behavior
I might be naive but I would expect every ServletContainerInitializer implementation to be instantiated respecting the configured order and its onStartup method being called immediately after (before any other ServletContainerInitializer implementation instantiation).