WW-5063 Adds null check for ActionInvocation
diff --git a/core/src/main/java/com/opensymphony/xwork2/ActionChainResult.java b/core/src/main/java/com/opensymphony/xwork2/ActionChainResult.java
index 06ab021..595107f 100644
--- a/core/src/main/java/com/opensymphony/xwork2/ActionChainResult.java
+++ b/core/src/main/java/com/opensymphony/xwork2/ActionChainResult.java
@@ -202,6 +202,10 @@
* @param invocation the DefaultActionInvocation calling the action call stack
*/
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
ValueStack stack = invocation.getInvocationContext().getValueStack();
String finalNamespace = this.namespace != null
? TextParseUtil.translateVariables(namespace, stack)
diff --git a/core/src/main/java/com/opensymphony/xwork2/Result.java b/core/src/main/java/com/opensymphony/xwork2/Result.java
index e92467b..8c1687e 100644
--- a/core/src/main/java/com/opensymphony/xwork2/Result.java
+++ b/core/src/main/java/com/opensymphony/xwork2/Result.java
@@ -45,6 +45,6 @@
* @param invocation the invocation context.
* @throws Exception can be thrown.
*/
- public void execute(ActionInvocation invocation) throws Exception;
+ void execute(ActionInvocation invocation) throws Exception;
}
diff --git a/core/src/main/java/org/apache/struts2/result/HttpHeaderResult.java b/core/src/main/java/org/apache/struts2/result/HttpHeaderResult.java
index 39395ab..a5d63b7 100644
--- a/core/src/main/java/org/apache/struts2/result/HttpHeaderResult.java
+++ b/core/src/main/java/org/apache/struts2/result/HttpHeaderResult.java
@@ -172,8 +172,12 @@
* @throws Exception if an error occurs when re-setting the headers.
*/
public void execute(ActionInvocation invocation) throws Exception {
- HttpServletResponse response = ServletActionContext.getResponse();
- ValueStack stack = ActionContext.getContext().getValueStack();
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
+ HttpServletResponse response = invocation.getInvocationContext().getServletResponse();
+ ValueStack stack = invocation.getStack();
if (status != -1) {
response.setStatus(status);
diff --git a/core/src/main/java/org/apache/struts2/result/PlainResult.java b/core/src/main/java/org/apache/struts2/result/PlainResult.java
index b398b93..172f6b6 100644
--- a/core/src/main/java/org/apache/struts2/result/PlainResult.java
+++ b/core/src/main/java/org/apache/struts2/result/PlainResult.java
@@ -45,6 +45,10 @@
@Override
default void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
LOG.debug("Executing plain result");
ResponseBuilder builder = new ResponseBuilder();
write(builder);
diff --git a/core/src/main/java/org/apache/struts2/result/PostbackResult.java b/core/src/main/java/org/apache/struts2/result/PostbackResult.java
index 261404d..1fc8c6e 100644
--- a/core/src/main/java/org/apache/struts2/result/PostbackResult.java
+++ b/core/src/main/java/org/apache/struts2/result/PostbackResult.java
@@ -110,6 +110,10 @@
@Override
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
String postbackUri = makePostbackUri(invocation);
setLocation(postbackUri);
super.execute(invocation);
diff --git a/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java b/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java
index ed6825b..dc6ac21 100644
--- a/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java
+++ b/core/src/main/java/org/apache/struts2/result/ServletActionRedirectResult.java
@@ -158,6 +158,10 @@
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
*/
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
actionName = conditionalParse(actionName, invocation);
parseLocation = false;
if (namespace == null) {
diff --git a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java
index 9d7b461..d59214b 100644
--- a/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java
+++ b/core/src/main/java/org/apache/struts2/result/ServletRedirectResult.java
@@ -143,6 +143,10 @@
}
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
if (anchor != null) {
anchor = conditionalParse(anchor, invocation);
}
diff --git a/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java b/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
index 9b82fd4..d310a6d 100644
--- a/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
+++ b/core/src/main/java/org/apache/struts2/views/xslt/XSLTResult.java
@@ -146,6 +146,10 @@
}
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
long startTime = System.currentTimeMillis();
String location = getStylesheetLocation();
@@ -154,12 +158,12 @@
}
if (parse) {
- ValueStack stack = ActionContext.getContext().getValueStack();
+ ValueStack stack = invocation.getStack();
location = TextParseUtil.translateVariables(location, stack);
}
try {
- HttpServletResponse response = ServletActionContext.getResponse();
+ HttpServletResponse response = invocation.getInvocationContext().getServletResponse();
response.setStatus(status);
response.setCharacterEncoding(encoding);
PrintWriter writer = response.getWriter();
diff --git a/core/src/site/resources/tags/action-attributes.html b/core/src/site/resources/tags/action-attributes.html
index c9e7e7c..7ff6035 100644
--- a/core/src/site/resources/tags/action-attributes.html
+++ b/core/src/site/resources/tags/action-attributes.html
@@ -67,6 +67,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/bean-attributes.html b/core/src/site/resources/tags/bean-attributes.html
index eca94fc..f079c8f 100644
--- a/core/src/site/resources/tags/bean-attributes.html
+++ b/core/src/site/resources/tags/bean-attributes.html
@@ -27,6 +27,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/date-attributes.html b/core/src/site/resources/tags/date-attributes.html
index 66b4414..38afc8f 100644
--- a/core/src/site/resources/tags/date-attributes.html
+++ b/core/src/site/resources/tags/date-attributes.html
@@ -51,6 +51,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/iterator-attributes.html b/core/src/site/resources/tags/iterator-attributes.html
index ffea921..fdc1cb7 100644
--- a/core/src/site/resources/tags/iterator-attributes.html
+++ b/core/src/site/resources/tags/iterator-attributes.html
@@ -59,6 +59,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/number-attributes.html b/core/src/site/resources/tags/number-attributes.html
index c98f6dd..73f91c2 100644
--- a/core/src/site/resources/tags/number-attributes.html
+++ b/core/src/site/resources/tags/number-attributes.html
@@ -99,6 +99,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/set-attributes.html b/core/src/site/resources/tags/set-attributes.html
index e52aded..1722cf3 100644
--- a/core/src/site/resources/tags/set-attributes.html
+++ b/core/src/site/resources/tags/set-attributes.html
@@ -19,7 +19,7 @@
<td align="left" valign="top">action</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">The scope in which to assign the variable. Can be <b>application</b>, <b>session</b>, <b>request</b>, <b>page</b>, or <b>action</b>.</td>
+ <td align="left" valign="top">The scope in which to assign the variable. Can be <b>application</b>, <b>session</b>, <b>request</b>, <b>page</b>, or <b>action</b> (action scope <em>also</em> adds it to the page scope).</td>
</tr>
<tr>
<td align="left" valign="top">trimBody</td>
@@ -43,6 +43,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (default scope: action,<em>override</em> with the scope attribute).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/text-attributes.html b/core/src/site/resources/tags/text-attributes.html
index 97e7bf4..bce06e6 100644
--- a/core/src/site/resources/tags/text-attributes.html
+++ b/core/src/site/resources/tags/text-attributes.html
@@ -59,6 +59,6 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
</table>
diff --git a/core/src/site/resources/tags/url-attributes.html b/core/src/site/resources/tags/url-attributes.html
index 843aec1..06e7d99 100644
--- a/core/src/site/resources/tags/url-attributes.html
+++ b/core/src/site/resources/tags/url-attributes.html
@@ -123,7 +123,7 @@
<td align="left" valign="top"></td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">String</td>
- <td align="left" valign="top">Name used to reference the value pushed into the Value Stack</td>
+ <td align="left" valign="top">Name used to reference the value pushed into the Value Stack (scope: action).</td>
</tr>
<tr>
<td align="left" valign="top">windowState</td>
diff --git a/core/src/test/java/org/apache/struts2/result/HttpHeaderResultTest.java b/core/src/test/java/org/apache/struts2/result/HttpHeaderResultTest.java
index 4a79dd3..640804e 100644
--- a/core/src/test/java/org/apache/struts2/result/HttpHeaderResultTest.java
+++ b/core/src/test/java/org/apache/struts2/result/HttpHeaderResultTest.java
@@ -118,7 +118,10 @@
result = new HttpHeaderResult();
responseMock = new Mock(HttpServletResponse.class);
response = (HttpServletResponse) responseMock.proxy();
- invocation = (ActionInvocation) new Mock(ActionInvocation.class).proxy();
+ Mock invocationMock = new Mock(ActionInvocation.class);
+ invocationMock.expectAndReturn("getInvocationContext", ActionContext.getContext());
+ invocationMock.expectAndReturn("getStack", ActionContext.getContext().getValueStack());
+ invocation = (ActionInvocation) invocationMock.proxy();
reflectionProvider = container.getInstance(ReflectionProvider.class);
ServletActionContext.setResponse(response);
}
diff --git a/plugins/gxp/src/main/java/org/apache/struts2/views/gxp/GxpResult.java b/plugins/gxp/src/main/java/org/apache/struts2/views/gxp/GxpResult.java
index 1e7eba6..701be88 100644
--- a/plugins/gxp/src/main/java/org/apache/struts2/views/gxp/GxpResult.java
+++ b/plugins/gxp/src/main/java/org/apache/struts2/views/gxp/GxpResult.java
@@ -104,9 +104,13 @@
/**
* Tells the GXP to write itself to the output stream.
*
- * @param actionInvocation the action invocation
+ * @param invocation the action invocation
*/
- public void execute(ActionInvocation actionInvocation) {
+ public void execute(ActionInvocation invocation) {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
GxpResourceProvider provider = getProvider();
try {
getGxpClosure().write(provider.getWriter(), new GxpContext(provider.getLocale(), outputXml));
@@ -114,7 +118,7 @@
throw new RuntimeException("Exception while rendering "
+ getGxpName()
+ " coming from "
- + actionInvocation.getAction().getClass().getName() + ".",
+ + invocation.getAction().getClass().getName() + ".",
e);
}
}
diff --git a/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java b/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
index e1b83c7..2161ef0 100644
--- a/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
+++ b/plugins/json/src/main/java/org/apache/struts2/json/JSONResult.java
@@ -185,6 +185,10 @@
}
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
ActionContext actionContext = invocation.getInvocationContext();
HttpServletRequest request = actionContext.getServletRequest();
HttpServletResponse response = actionContext.getServletResponse();
diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java
index 282f653..eaef67c 100644
--- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java
+++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java
@@ -171,6 +171,10 @@
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
*/
public void execute(ActionInvocation invocation) throws Exception {
+ if (invocation == null) {
+ throw new IllegalArgumentException("Invocation cannot be null!");
+ }
+
actionName = conditionalParse(actionName, invocation);
parseLocation = false;