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

The contains method of org.apache.struts2.util.ContainUtil throws a NullPointerException if Obj1 contains a null element in an array

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.1.6, 2.1.8
    • Fix Version/s: 2.1.8
    • Component/s: Other
    • Labels:
      None
    • Environment:

      All

    • Flags:
      Patch, Important

      Description

      The code for dealing with an array in the contains class needs to be swapped to prevent a NPE. The solution is trivial and involves swapping the order of the equals test for Arrays to be inline with that used for Iterable.

      Currently the code is :

      ...else if (obj1.getClass().isArray()) {
      for (int i = 0; i < Array.getLength(obj1); i++) {
      Object value = null;
      value = Array.get(obj1, i);

      if (value.equals(obj2))

      { // throws NPE if array contains null element //log.debug("obj1 is an array and contains obj2"); return true; }

      }
      }

      When it should be :

      ...else if (obj1.getClass().isArray()) {
      for (int i = 0; i < Array.getLength(obj1); i++) {
      Object value = null;
      value = Array.get(obj1, i);

      if (obj2.equals(value))

      { // change the order of the equals test to prevent NPE //log.debug("obj1 is an array and contains obj2"); return true; }

      }
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              zoran Zoran Avtarovski
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: