kusalk commented on code in PR #969:
URL: https://github.com/apache/struts/pull/969#discussion_r1644161012


##########
core/src/main/java/com/opensymphony/xwork2/interceptor/ValidationAware.java:
##########
@@ -119,7 +119,9 @@ public interface ValidationAware {
      *
      * @return <code>(hasActionErrors() || hasFieldErrors())</code>
      */
-    boolean hasErrors();
+    default boolean hasErrors() {

Review Comment:
   Added default implementation which matches the JavaDoc, makes implementing 
this class simpler



##########
core/src/main/java/com/opensymphony/xwork2/util/DebugUtils.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.opensymphony.xwork2.util;
+
+import com.opensymphony.xwork2.TextProvider;
+import com.opensymphony.xwork2.interceptor.ValidationAware;
+import org.apache.logging.log4j.Logger;
+
+/**
+ * @since 6.5.0
+ */
+public class DebugUtils {
+
+    public static void notifyDeveloperOfError(Logger log, Object action, 
String message) {

Review Comment:
   Extracted this method out of `ParametersInterceptor` for reuse



##########
core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java:
##########
@@ -116,15 +116,17 @@ public void testInsecureParameters() throws Exception {
         pi.setParameters(action, vs, HttpParameters.create(params).build());
 
         // then
-        assertEquals(3, action.getActionMessages().size());
+        assertEquals(3, action.getActionErrors().size());
 
-        String msg1 = action.getActionMessage(0);
-        String msg2 = action.getActionMessage(1);
-        String msg3 = action.getActionMessage(2);
+        List<String> actionErrors = new ArrayList<>(action.getActionErrors());
 
-        assertEquals("Error setting expression 'expression' with value 
'#f=#_memberAccess.getClass().getDeclaredField('allowStaticMethodAccess'),#f.setAccessible(true),#f.set(#_memberAccess,true),#[email protected]@getRequest(),#[email protected]@getResponse().getWriter(),#resp.println(#req.getRealPath('/')),#resp.close()'",
 msg1);
-        assertEquals("Error setting expression 'name' with value 
'(#context[\"xwork.MethodAccessor.denyMethodExecution\"]= new 
java.lang.Boolean(false), #_memberAccess[\"allowStaticMethodAccess\"]= new 
java.lang.Boolean(true), @java.lang.Runtime@getRuntime().exec('mkdir 
/tmp/PWNAGE'))(meh)'", msg2);
-        assertEquals("Error setting expression 'top['name'](0)' with value 
'true'", msg3);
+        String msg1 = actionErrors.get(0);
+        String msg2 = actionErrors.get(1);
+        String msg3 = actionErrors.get(2);
+
+        assertEquals("Unexpected Exception caught setting 'expression' on 
'class org.apache.struts2.interceptor.parameter.ValidateAction: Error setting 
expression 'expression' with value 
'#f=#_memberAccess.getClass().getDeclaredField('allowStaticMethodAccess'),#f.setAccessible(true),#f.set(#_memberAccess,true),#[email protected]@getRequest(),#[email protected]@getResponse().getWriter(),#resp.println(#req.getRealPath('/')),#resp.close()'",
 msg1);

Review Comment:
   These messages now include both the context message as well as the exception 
message. Whilst they are very similar in this test example, it's not guaranteed 
to be the case



##########
core/src/main/java/com/opensymphony/xwork2/ognl/ErrorMessageBuilder.java:
##########
@@ -42,7 +42,7 @@ public ErrorMessageBuilder 
errorSettingExpressionWithValue(String expr, Object v
         return this;
     }
 
-    private void appenExpression(String expr) {
+    private void appendExpression(String expr) {

Review Comment:
   Fixed typo



##########
core/src/test/java/org/apache/struts2/interceptor/parameter/ParametersInterceptorTest.java:
##########
@@ -116,15 +116,17 @@ public void testInsecureParameters() throws Exception {
         pi.setParameters(action, vs, HttpParameters.create(params).build());
 
         // then
-        assertEquals(3, action.getActionMessages().size());
+        assertEquals(3, action.getActionErrors().size());

Review Comment:
   Using Action errors instead of Action messages to communicate developer 
errors (only impacts DevMode)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to