This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new fe116248ead CAMEL-19199: camel-plc4x - Fix NPE with no tags configured. fe116248ead is described below commit fe116248ead3e8b18c92bbb3d68751cde1d0e817 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Mon Mar 27 10:42:55 2023 +0200 CAMEL-19199: camel-plc4x - Fix NPE with no tags configured. --- .../org/apache/camel/component/plc4x/Plc4XEndpoint.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java index 1d8a51c639b..979d016a9af 100644 --- a/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java +++ b/components/camel-plc4x/src/main/java/org/apache/camel/component/plc4x/Plc4XEndpoint.java @@ -94,7 +94,7 @@ public class Plc4XEndpoint extends DefaultEndpoint { public void setTrigger(String trigger) { this.trigger = trigger; - plcDriverManager = new PooledPlcDriverManager(); + this.plcDriverManager = new PooledPlcDriverManager(); } public void setAutoReconnect(boolean autoReconnect) { @@ -190,12 +190,14 @@ public class Plc4XEndpoint extends DefaultEndpoint { */ public PlcReadRequest buildPlcReadRequest() { PlcReadRequest.Builder builder = connection.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.warn("For consumer, please use Map<String,String>, currently using {}", + tags.getClass().getSimpleName()); + } } } return builder.build(); @@ -268,6 +270,7 @@ public class Plc4XEndpoint extends DefaultEndpoint { //Shutting down the connection when leaving the Context if (connection != null && connection.isConnected()) { connection.close(); + connection = null; } }