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

OgnlTextParser contains a NPE when the expression is passed in as null

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.15
    • Fix Version/s: 2.3.16
    • Component/s: None
    • Labels:
      None

      Description

      Unfortunately, I haven't figured out the exact cause of the issue; however, the fix provided brings our system back to how it used to work.

      When expression is passed in a null, a NPE is thrown @:

      int start = expression.indexOf(lookupChars, pos);

              Object result = expression;
              int pos = 0;
      
              for (char open : openChars) {
                  int loopCount = 1;
                  //this creates an implicit StringBuffer and shouldn't be used in the inner loop
                  final String lookupChars = open + "{";
      
                  while (true) {
                      int start = expression.indexOf(lookupChars, pos);
                      if (start == -1) {
                          loopCount++;
                          start = expression.indexOf(lookupChars);
                      }
      

      Here is the fix I'm using in a locally built class file:

              Object result = expression = (expression == null) ? "" : expression;
              int pos = 0;
      
              for (char open : openChars) {
                  int loopCount = 1;
                  //this creates an implicit StringBuffer and shouldn't be used in the inner loop
                  final String lookupChars = open + "{";
      
                  while (true) {
                      int start = expression.indexOf(lookupChars, pos);
                      if (start == -1) {
                          loopCount++;
                          start = expression.indexOf(lookupChars);
                      }
      

      I can see about 10 different ways to 'fix' the issue, but this keeps the change to a single line since I don't entirely understand the workflow of what's going on.

      FYI, it seems to have something to do with validate="true" on the form and when there are fields to validate which have nested getters, aka:

      <@s.hidden key="myFakePatternHolder.pattern.id"/>

        Attachments

          Activity

            People

            • Assignee:
              lukaszlenart Lukasz Lenart
              Reporter:
              trumpetx David Greene
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: