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

Invalid OGNL expressions are not cached

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.3.14
    • 6.5.0
    • Value Stack
    • None

    Description

      I am using velocity to render results page. During performance optimizations I noticed significant memory usage from com.opensymphony.xwork2.ognl.OgnlUtil#compile. There is caching implemented in OgnlUtil, but if expression compilation fails, it is not cached.
      I am not really sure if this problem is in struts or velocity engine. But situation is following:

      1. In velocity template trying to render string <p>$!foo</p>
      2. If value is null, velocity calls org.apache.velocity.runtime.parser.node.ASTReference#getNullString
      3. Internally there is call to context.get(".literal." + nullString)
      4. And this ".literal." expression always reaches OgnlUtil#compile and compilation fails.

      Below is stacktrace for more details:

      at com.opensymphony.xwork2.ognl.OgnlUtil.compile(OgnlUtil.java:248)
      at com.opensymphony.xwork2.ognl.OgnlUtil.getValue(OgnlUtil.java:236)
      at com.opensymphony.xwork2.ognl.OgnlValueStack.getValueUsingOgnl(OgnlValueStack.java:291)
      at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValue(OgnlValueStack.java:274)
      at com.opensymphony.xwork2.ognl.OgnlValueStack.tryFindValueWhenExpressionIsNotNull(OgnlValueStack.java:256)
      at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:236)
      at com.opensymphony.xwork2.ognl.OgnlValueStack.findValue(OgnlValueStack.java:298)
      at org.apache.struts2.dispatcher.StrutsRequestWrapper.getAttribute(StrutsRequestWrapper.java:82)
      at org.apache.velocity.tools.view.context.ChainedContext.getAttribute(Unknown Source:-1)
      at org.apache.velocity.tools.view.context.ChainedContext.internalGet(Unknown Source:-1)
      at org.apache.velocity.context.AbstractContext.get(AbstractContext.java:193)
      at org.apache.velocity.context.InternalContextAdapterImpl.get(InternalContextAdapterImpl.java:267)
      at org.apache.velocity.runtime.parser.node.ASTReference.getNullString(ASTReference.java:510)
      at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:465)
      at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
      at org.apache.velocity.runtime.parser.node.ASTStringLiteral.value(ASTStringLiteral.java:330)
      at org.apache.velocity.runtime.parser.node.ASTExpression.value(ASTExpression.java:71)
      at org.apache.velocity.runtime.parser.node.ASTSetDirective.render(ASTSetDirective.java:142)
      at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
      at org.apache.velocity.runtime.directive.Parse.render(Parse.java:260)
      at org.apache.velocity.runtime.parser.node.ASTDirective.render(ASTDirective.java:207)
      at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
      at org.apache.velocity.Template.merge(Template.java:356)
      at org.apache.velocity.Template.merge(Template.java:260)
      at org.apache.struts2.dispatcher.VelocityResult.doExecute(VelocityResult.java:156)
      at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)
      

      Attachments

        1. WW-4062.PNG
          94 kB
          Saulius Tvarijonas

        Activity

          People

            Unassigned Unassigned
            saulius Saulius Tvarijonas
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: