gnodet-bot commented on code in PR #29007:
URL: https://github.com/apache/camel/pull/29007#discussion_r4448725850


##########
components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java:
##########
@@ -316,16 +319,30 @@ public PlcWriteRequest buildPlcWriteRequest(Map<String, 
Map<String, Object>> tag
         }
         PlcWriteRequest.Builder builder = current.writeRequestBuilder();
 
-        for (Map.Entry<String, Map<String, Object>> entry : tags.entrySet()) {
+        for (Map.Entry<String, ?> entry : tags.entrySet()) {
             //Tags are stored like this --> Map<Tagname,Map<Query,Value>> for 
writing
             String name = entry.getKey();
-            String query = entry.getValue().keySet().iterator().next();
-            Object value = entry.getValue().get(query);
-            builder.addTagAddress(name, query, value);
+            // the body of a message is not checked for these types, so a 
value may be anything
+            if (!(entry.getValue() instanceof Map<?, ?> queryAndValue) || 
queryAndValue.size() != 1
+                    || !(queryAndValue.keySet().iterator().next() instanceof 
String query)) {
+                // the exception ends the message with " invalid"
+                throw new PlcInvalidTagException(
+                        "Tag " + name + ": the value must be a Map of one 
address of the tag to the value to write,"
+                                                 + " such as {\"%DB1:DINT\": 
21}, but " + describe(entry.getValue())
+                                                 + " is");
+            }
+            builder.addTagAddress(name, query, queryAndValue.get(query));
         }
         return builder.build();
     }
 
+    private static String describe(Object value) {
+        if (value instanceof Map<?, ?> map) {
+            return map.isEmpty() ? "a Map without an address" : "a Map of " + 
map.size() + " addresses";

Review Comment:
   Minor grammar nit: when `map.size() == 1` and the key is not a `String` (so 
`describe()` is reachable with a size-1 map), this produces `"a Map of 1 
addresses"` instead of `"1 address"`.
   
   ```suggestion
               return map.isEmpty() ? "a Map without an address" : "a Map of " 
+ map.size() + (map.size() == 1 ? " address" : " addresses");
   ```



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