My application is based on struts2 (v 6.3.0.2) and I am currently using ognl v3.3.4 as one of its dependency. The application is working fine with these version.
When I try to uplift the OGNL to latest version i.e 3.4.2 I am getting the below error:
at com.opensymphony.xwork2.ognl.OgnlValueStack.setRoot(OgnlValueStack.java:102)
at com.opensymphony.xwork2.ognl.OgnlValueStack.<init>(OgnlValueStack.java:81)
at com.opensymphony.xwork2.ognl.OgnlValueStackFactory.createValueStack(OgnlValueStackFactory.java:62)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.setContext(DefaultConfiguration.java:244)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:208)
at com.opensymphony.xwork2.config.ConfigurationManager.reload(ConfigurationManager.java:227)
at com.opensymphony.xwork2.config.ConfigurationManager.initialiseConfiguration(ConfigurationManager.java:84)
at com.opensymphony.xwork2.config.ConfigurationManager.wasConfigInitialised(ConfigurationManager.java:72)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:61)
at org.apache.struts2.dispatcher.Dispatcher.getContainer(Dispatcher.java:1079)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:537)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:571)
at org.apache.struts2.dispatcher.InitOperations.initDispatcher(InitOperations.java:48)
at org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:60)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:262)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:244)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:97)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4311)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4940)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:683)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:658)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:661)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1014)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1866)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:118)
at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:816)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1584)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:312)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:114)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:402)
at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:345)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:893)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:794)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1332)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1322)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:866)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:248)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:433)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:925)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.startup.Catalina.start(Catalina.java:735)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:345)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:476)
from what I have found out is that ognl.OgnlValueStack.setRoot
calls ognl.Ognl.createDefaultContext
.
In 3.3.4 createDefaultContext
return type was Map
.
In 3.4.2 createDefaultContext
return type is OgnlContext
.
This incompatibility is the cause of error, but is there any solution to that from my code perspective? or its simply OGNL (3.4.2) is not compatible with struts2 (6.3.0.2).
The OgnlContext
ia a Map<String, Object>
. In Struts 2 OgnlContext
is set to ActionContext
and ValueStack
is a root object in it. For more information read:
The framework sets the OGNL context to be our
ActionContext
, and theValueStack
to be the OGNL root object. (TheValueStack
is a set of several objects, but to OGNL it appears to be a single object). Along with the value stack, the framework places other objects in theActionContext
, including maps representing the application, session, and request contexts. These objects coexist in theActionContext
, alongside the value stack (our OGNL root).
The ActionContext
is not a Map<String, Object>
, but you can get a context map with
OgnlContext context = (OgnlContext) ActionContext.getContext().getContextMap();
The ValuStack
has there own context. There's also a Map<String, Object>
you can get
OgnlContext context = (OgnlContext) ActionContext.getContext().getValueStack().getContext();
Which version you use depends on implementation. You cannot just uplift a version of the API and use it with artifacts that require a lower version.