This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-3.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.20.x by this push:
     new 66333ea3bf1 CAMEL-19199: camel-plc4x - Fix NPE with no tags configured.
66333ea3bf1 is described below

commit 66333ea3bf17e56d8cb6bacc7e235a7968d5847a
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Mar 27 10:45:49 2023 +0200

    CAMEL-19199: camel-plc4x - Fix NPE with no tags configured.
---
 .../camel/component/plc4x/Plc4XConsumer.java       | 33 ++++++++++++----------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git 
a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XConsumer.java
 
b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XConsumer.java
index c7b74c8aefc..094966b3e63 100644
--- 
a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XConsumer.java
+++ 
b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XConsumer.java
@@ -86,12 +86,14 @@ public class Plc4XConsumer extends DefaultConsumer {
 
     private void startUnTriggered() {
         PlcReadRequest.Builder builder = plcConnection.readRequestBuilder();
-        for (Map.Entry<String, Object> tag : tags.entrySet()) {
-            try {
-                builder.addItem(tag.getKey(), (String) tag.getValue());
-            } catch (PlcIncompatibleDatatypeException e) {
-                LOGGER.error("For consumer, please use Map<String,String>, 
currently using {}",
-                        tags.getClass().getSimpleName());
+        if (tags != null) {
+            for (Map.Entry<String, Object> tag : tags.entrySet()) {
+                try {
+                    builder.addItem(tag.getKey(), (String) tag.getValue());
+                } catch (PlcIncompatibleDatatypeException e) {
+                    LOGGER.error("For consumer, please use Map<String,String>, 
currently using {}",
+                            tags.getClass().getSimpleName());
+                }
             }
         }
         PlcReadRequest request = builder.build();
@@ -129,17 +131,18 @@ public class Plc4XConsumer extends DefaultConsumer {
 
     private Map<String, String> validateTags() {
         Map<String, String> map = new HashMap<>();
-        for (Map.Entry<String, Object> tag : tags.entrySet()) {
-            if (tag.getValue() instanceof String) {
-                map.put(tag.getKey(), (String) tag.getValue());
+        if (tags != null) {
+            for (Map.Entry<String, Object> tag : tags.entrySet()) {
+                if (tag.getValue() instanceof String) {
+                    map.put(tag.getKey(), (String) tag.getValue());
+                }
+            }
+            if (map.size() != tags.size()) {
+                LOGGER.error("At least one entry does not match the format : 
Map.Entry<String,String> ");
+                return null;
             }
         }
-        if (map.size() != tags.size()) {
-            LOGGER.error("At least one entry does not match the format : 
Map.Entry<String,String> ");
-            return null;
-        } else {
-            return map;
-        }
+        return map;
     }
 
     private ScraperConfigurationTriggeredImpl getScraperConfig(Map<String, 
String> tagList) {

Reply via email to