This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.x by this push:
new 2dd7adb9989 CAMEL-19199: camel-plc4x - Fix NPE with no tags configured.
2dd7adb9989 is described below
commit 2dd7adb99898005945882ee0527d315f7a2d451d
Author: Claus Ibsen <[email protected]>
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;
}
}