ChiangHaosion commented on code in PR #18741:
URL: 
https://github.com/apache/dolphinscheduler/pull/18741#discussion_r4396741291


##########
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-http/src/main/java/org/apache/dolphinscheduler/plugin/alert/http/HttpSender.java:
##########
@@ -217,12 +218,52 @@ private void setMsgInRequestBody(String msg) {
             return;
         }
 
-        bodyParams.forEach((key, value) -> {
-            String valueOf = String.valueOf(value);
-            if (valueOf.contains(HttpAlertConstants.MSG_PARAMS)) {
-                bodyParams.put(key, 
valueOf.replace(HttpAlertConstants.MSG_PARAMS, msg));
+        if (msg == null) {
+            if (containsMsgPlaceholder(bodyParams)) {
+                throw new RuntimeException(
+                        String.format("alert content is null, can not replace 
%s in the body params",
+                                HttpAlertConstants.MSG_PARAMS));
             }
-        });
+            return;
+        }
+
+        replaceMsg(bodyParams, msg);
+    }
+
+    /**
+     * Whether the body params require an alert message, so that a static body 
without the
+     * placeholder can still be sent when the message is null.
+     */
+    @SuppressWarnings("unchecked")
+    private boolean containsMsgPlaceholder(Object value) {
+        if (value instanceof String) {
+            return ((String) value).contains(HttpAlertConstants.MSG_PARAMS);
+        }
+        if (value instanceof Map) {
+            return ((Map<Object, Object>) 
value).values().stream().anyMatch(this::containsMsgPlaceholder);
+        }
+        if (value instanceof List) {
+            return ((List<Object>) 
value).stream().anyMatch(this::containsMsgPlaceholder);
+        }
+        return false;
+    }
+
+    /**
+     * Recursively replace ${msg} in string nodes while keeping the json 
structure,
+     * so that nested objects/arrays are not flattened into a string.
+     * Characters in msg are escaped by Jackson when the request body is 
serialized.
+     */
+    @SuppressWarnings("unchecked")

Review Comment:
   @SbloodyS  OK.Dropped in a15bf5e890. the walk now casts to `Map<?, ?>` / 
`List<?>`  and rebuilds nested nodes into `LinkedHashMap` / `ArrayList` instead 
of mutating them in place; in-place mutation was the only reason a concrete 
cast was needed. The tests read the recorded body as a `JsonNode` tree, so 
their suppressions are gone too. Clean `mvn test` compile reports no unchecked 
operations, 6/6 pass.



-- 
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