WW-5063 Adds null check for ActionInvocation

This commit is contained in:
Lukasz Lenart
2020-12-24 15:45:46 +01:00
parent 7532d2fb0d
commit f2540192bf
20 changed files with 61 additions and 18 deletions
@@ -202,6 +202,10 @@ public class ActionChainResult implements Result {
* @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)
@@ -45,6 +45,6 @@ public interface Result extends Serializable {
* @param invocation the invocation context.
* @throws Exception can be thrown.
*/
public void execute(ActionInvocation invocation) throws Exception;
void execute(ActionInvocation invocation) throws Exception;
}
@@ -172,8 +172,12 @@ public class HttpHeaderResult implements Result {
* @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);
@@ -45,6 +45,10 @@ public interface PlainResult extends Result {
@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);
@@ -110,6 +110,10 @@ public class PostbackResult extends StrutsResultSupport {
@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);
@@ -158,6 +158,10 @@ public class ServletActionRedirectResult extends ServletRedirectResult implement
* @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) {
@@ -143,6 +143,10 @@ public class ServletRedirectResult extends StrutsResultSupport implements Reflec
}
public void execute(ActionInvocation invocation) throws Exception {
if (invocation == null) {
throw new IllegalArgumentException("Invocation cannot be null!");
}
if (anchor != null) {
anchor = conditionalParse(anchor, invocation);
}
@@ -146,6 +146,10 @@ public class XSLTResult implements Result {
}
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 @@ public class XSLTResult implements Result {
}
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();
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -118,7 +118,10 @@ public class HttpHeaderResultTest extends StrutsInternalTestCase {
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);
}
@@ -104,9 +104,13 @@ public class GxpResult extends AbstractGxpResult {
/**
* 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 @@ public class GxpResult extends AbstractGxpResult {
throw new RuntimeException("Exception while rendering "
+ getGxpName()
+ " coming from "
+ actionInvocation.getAction().getClass().getName() + ".",
+ invocation.getAction().getClass().getName() + ".",
e);
}
}
@@ -185,6 +185,10 @@ public class JSONResult implements Result {
}
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();
@@ -171,6 +171,10 @@ public class PortletActionRedirectResult extends PortletResult {
* @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;