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

NullPointerException when displaying a form without action attribute

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.3.28, 2.3.29, 2.3.30
    • Fix Version/s: 2.5.12
    • Component/s: None
    • Labels:
      None

      Description

      Hello,

      I'm currently trying to upgrade Struts from V2.3.20 to V2.3.30.
      Starting from V2.3.28, I'm having a yellow FreeMarker stack at the end of some pages. These pages have a <s:form> tag without "action" attribute.

      Here is some part of the displayed error :

      Java method "org.apache.struts2.components.Form.getValidators(String)" threw an exception when invoked on org.apache.struts2.components.Form object "org.apache.struts2.components.Form@3d354929"; see cause exception in the Java stack trace.
      FTL stack trace ("~" means nesting-related):
      	- Failed at: #list tag.getValidators("\$\{tagName\}"...  [in template "template/~~~css_xhtml/form-close-validate.ftl" at line 66, column 9]
      	- Reached through: #include "/\$\{parameters.templateDir\}...  [in template "template/xhtml/form-close.ftl" at line 25, column 1]
      ...
      Caused by: java.lang.NullPointerException
      	at org.apache.struts2.util.ComponentUtils.containsExpression(ComponentUtils.java:51)
      	at org.apache.struts2.components.Component.findValue(Component.java:376)
      	at org.apache.struts2.components.Component.findString(Component.java:226)
      	at org.apache.struts2.components.Form.getValidators(Form.java:276)
      

      Here are the results of my research :

      • When the method org.apache.struts2.components.Form.getValidators(String name) is called at the end of the page display, the "action" var is null.
      • findString(action) is called, leading to org.apache.struts2.components.Component.findValue(String expr, Class toType) with expr=null
      • Starting from V2.3.28, a new condition has been added to this method : if (ComponentUtils.containsExpression(expr)). This raises the NPE.

      Is this a bug, or am I doing something wrong ?

      Thanks in advance,
      Yan

        Activity

        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit cc0d52f216f97df296dd136b34af708c19a741ea in struts's branch refs/heads/support-2-3 from Lukasz Lenart
        [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=cc0d52f ]

        WW-4663 Checks if expression is null to avoid NPE

        Show
        jira-bot ASF subversion and git services added a comment - Commit cc0d52f216f97df296dd136b34af708c19a741ea in struts's branch refs/heads/support-2-3 from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=cc0d52f ] WW-4663 Checks if expression is null to avoid NPE
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 7dbe3ea8bb97cd004e77541c761bbe20e4373c3d in struts's branch refs/heads/master from Lukasz Lenart
        [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=7dbe3ea ]

        WW-4663 Checks if expression is null to avoid NPE

        Show
        jira-bot ASF subversion and git services added a comment - Commit 7dbe3ea8bb97cd004e77541c761bbe20e4373c3d in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=7dbe3ea ] WW-4663 Checks if expression is null to avoid NPE
        Hide
        lukaszlenart Lukasz Lenart added a comment -

        Resolved

        Show
        lukaszlenart Lukasz Lenart added a comment - Resolved
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build Struts-JDK6-support-2.3 #1046 (See https://builds.apache.org/job/Struts-JDK6-support-2.3/1046/)
        WW-4663 Checks if expression is null to avoid NPE (lukaszlenart: rev cc0d52f216f97df296dd136b34af708c19a741ea)

        • (edit) core/src/main/java/org/apache/struts2/util/ComponentUtils.java
        • (edit) core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK6-support-2.3 #1046 (See https://builds.apache.org/job/Struts-JDK6-support-2.3/1046/ ) WW-4663 Checks if expression is null to avoid NPE (lukaszlenart: rev cc0d52f216f97df296dd136b34af708c19a741ea) (edit) core/src/main/java/org/apache/struts2/util/ComponentUtils.java (edit) core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build Struts-JDK7-master #515 (See https://builds.apache.org/job/Struts-JDK7-master/515/)
        WW-4663 Checks if expression is null to avoid NPE (lukaszlenart: rev 7dbe3ea8bb97cd004e77541c761bbe20e4373c3d)

        • (edit) core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java
        • (edit) core/src/main/java/org/apache/struts2/util/ComponentUtils.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #515 (See https://builds.apache.org/job/Struts-JDK7-master/515/ ) WW-4663 Checks if expression is null to avoid NPE (lukaszlenart: rev 7dbe3ea8bb97cd004e77541c761bbe20e4373c3d) (edit) core/src/test/java/org/apache/struts2/util/ComponentUtilsTest.java (edit) core/src/main/java/org/apache/struts2/util/ComponentUtils.java
        Hide
        Yan Soulliaert Yan Soulliaert added a comment -

        Hello,

        I upgraded Struts to 2.3.31 and I still have a NullPointerException, but not at the same place.

        Here is the NPE stack :
        Caused by: java.lang.NullPointerException
        at org.apache.struts2.components.Form.getValidators(Form.java:278)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1458)
        at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:71)
        ... 235 more

        Following your previous correction, the call to findString(action) in the Form class (l276) returns null.
        Thus "ActionMapping mapping" is null, causing the NPE.

        Thanks in advance !

        Show
        Yan Soulliaert Yan Soulliaert added a comment - Hello, I upgraded Struts to 2.3.31 and I still have a NullPointerException, but not at the same place. Here is the NPE stack : Caused by: java.lang.NullPointerException at org.apache.struts2.components.Form.getValidators(Form.java:278) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:1458) at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:71) ... 235 more Following your previous correction, the call to findString(action) in the Form class (l276) returns null. Thus "ActionMapping mapping" is null, causing the NPE. Thanks in advance !
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 1162ddf823b9d47df080fd273f1da22e088eda72 in struts's branch refs/heads/master from Lukasz Lenart
        [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=1162ddf ]

        WW-4663 Fallback to old behaviour if there is no action defined

        Show
        jira-bot ASF subversion and git services added a comment - Commit 1162ddf823b9d47df080fd273f1da22e088eda72 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=1162ddf ] WW-4663 Fallback to old behaviour if there is no action defined
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Jenkins build Struts-JDK7-master #615 (See https://builds.apache.org/job/Struts-JDK7-master/615/)
        WW-4663 Fallback to old behaviour if there is no action defined (lukaszlenart: rev 1162ddf823b9d47df080fd273f1da22e088eda72)

        • (edit) core/src/main/java/org/apache/struts2/components/Form.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #615 (See https://builds.apache.org/job/Struts-JDK7-master/615/ ) WW-4663 Fallback to old behaviour if there is no action defined (lukaszlenart: rev 1162ddf823b9d47df080fd273f1da22e088eda72) (edit) core/src/main/java/org/apache/struts2/components/Form.java

          People

          • Assignee:
            lukaszlenart Lukasz Lenart
            Reporter:
            Yan Soulliaert Yan Soulliaert
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development