Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4262

TextParseUtil.translateVariables throws NPE when called from Interceptor Init() method

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.15.1, 2.3.15.3, 2.3.16
    • Fix Version/s: 2.3.20
    • Component/s: Value Stack
    • Labels:
      None
    • Environment:

      Mac OSX - JDK 1.7_0_25 and 45

      Description

      The key thing to remember is this problem does
      not occur using Struts 2.3.4.1. There are a couple of false
      indicators that I have worked through and I do believe this is due to
      a recent change in the code. I have debugged it thoroughly and would
      appreciate any pointers in the right direction.

      I have tested this on MAC/OSX with Java 7u25 and 7u45, and tomcat
      7047, 800rc5, 800rc9 as well.

      Call to TextParseUtil.translateVariable throws Null Pointer exception.

      This happens when I call

      TextProviderFactory.createInstance(Class,LocaleProvider).getText(String)

      from an "init()" method of an interceptor.

      This works fine in struts 2.3.4.1. After upgrading to 2.3.15.1,
      2.3.15.3 and 2.3.16, the server fails to deploy the application with
      the following exception:

      SEVERE: Actual exception
      Caught Exception while registering Interceptor class example.HitachiTestInterceptor - interceptor - file:/Users/andrewcarr/Documents/work-workspace-kepler-ee/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts2-10243/WEB-INF/classes/struts.xml:14:98
              at org.apache.struts2.impl.StrutsObjectFactory.buildInterceptor(StrutsObjectFactory.java:77)
              at com.opensymphony.xwork2.config.providers.InterceptorBuilder.constructInterceptorReference(InterceptorBuilder.java:70)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.lookupInterceptorReference(XmlConfigurationProvider.java:1110)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStack(XmlConfigurationProvider.java:928)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptorStacks(XmlConfigurationProvider.java:941)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadInterceptors(XmlConfigurationProvider.java:964)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:533)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildPackageContext(XmlConfigurationProvider.java:666)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addPackage(XmlConfigurationProvider.java:519)
              at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.loadPackages(XmlConfigurationProvider.java:292)
              at org.apache.struts2.config.StrutsXmlConfigurationProvider.loadPackages(StrutsXmlConfigurationProvider.java:112)
              at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:250)
              at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
              at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:446)
              at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:490)
              at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
              at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
              at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
              at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
              at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
              at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
              at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
              at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
              at java.util.concurrent.FutureTask.run(FutureTask.java:166)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
              at java.lang.Thread.run(Thread.java:722)
      Caused by: java.lang.NullPointerException
              at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:170)
              at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:127)
              at com.opensymphony.xwork2.util.TextParseUtil.translateVariables(TextParseUtil.java:49)
              at com.opensymphony.xwork2.util.LocalizedTextUtil.getMessage(LocalizedTextUtil.java:683)
              at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:467)
              at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:362)
              at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:208)
              at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:123)
              at example.TextUtil.getText(TextUtil.java:59)
              at example.HitachiTestInterceptor.init(HitachiTestInterceptor.java:29)
              at org.apache.struts2.impl.StrutsObjectFactory.buildInterceptor(StrutsObjectFactory.java:57)
              ... 29 more
      

      The full stack trace is available here:
      http://pastebin.com/Us7AFxWT

      I have debugged the code update. It appears this is happening when
      calling ValueStack#findValue(java.lang.String) from the interceptor.

      I have time to work on a patch, if this issue is valid.

        Attachments

          Activity

            People

            • Assignee:
              lukaszlenart Lukasz Lenart
              Reporter:
              aliasdhacker Andrew Carr
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 12h
                12h
                Remaining:
                Remaining Estimate - 12h
                12h
                Logged:
                Time Spent - Not Specified
                Not Specified