Skip to content

Commit 5c73dfe

Browse files
committed
fix(plc4j/opcua): Fix null pointer exception in OPC UA Subscription Handle.
The 'sampling' mode in case of OPC-UA means that no actual events are generated to the client. This is a sort of 'suspended' subscription which will deliver its events once monitoring item is switched back to reporting mode. In essence all UA subscriptions must be in reporting mode to generate data for client. Closes #2024. Signed-off-by: Łukasz Dywicki <[email protected]>
1 parent 05d7414 commit 5c73dfe

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

plc4j/drivers/opcua/src/main/java/org/apache/plc4x/java/opcua/protocol/OpcuaSubscriptionHandle.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ public CompletableFuture<OpcuaSubscriptionHandle> onSubscribeCreateMonitoredItem
107107
new QualifiedName(0, OpcuaProtocolLogic.NULL_STRING));
108108

109109
MonitoringMode monitoringMode = MonitoringMode.monitoringModeReporting;
110-
if (PlcSubscriptionType.CYCLIC == tagDefaultPlcSubscription.getPlcSubscriptionType()) {
111-
monitoringMode = MonitoringMode.monitoringModeSampling;
112-
}
113-
114110
ExtensionObject eventFilter = OpcuaProtocolLogic.NULL_EXTENSION_OBJECT;
115111
if (tagDefaultPlcSubscription.getPlcSubscriptionType() == PlcSubscriptionType.EVENT) {
116112
NodeId nodeId = new NodeId(new NodeIdFourByte((short) 0, OpcuaNodeIdServicesObjectType.BaseEventType.getValue()));
@@ -219,22 +215,25 @@ private void sendPublishRequest() {
219215
outstandingAcknowledgements.add(new SubscriptionAcknowledgement(this.subscriptionId, availableSequenceNumber));
220216
}
221217

222-
for (ExtensionObject notificationMessage : responseMessage.getNotificationMessage().getNotificationData()) {
223-
ExtensionObjectDefinition notification = notificationMessage.getBody();
224-
if (notification instanceof DataChangeNotification) {
225-
logger.trace("Found a Data Change Notification");
226-
DataChangeNotification data = (DataChangeNotification) notification;
227-
if (!data.getMonitoredItems().isEmpty()) {
228-
onMonitoredValue(data.getMonitoredItems());
229-
}
230-
} else if (notification instanceof EventNotificationList) {
231-
logger.trace("Found a Event Notification");
232-
EventNotificationList data = (EventNotificationList) notification;
233-
if (!data.getEvents().isEmpty()) {
234-
onEventNotification(data.getEvents());
218+
NotificationMessage message = responseMessage.getNotificationMessage();
219+
if (message.getNotificationData() != null) {
220+
for (ExtensionObject notificationMessage : message.getNotificationData()) {
221+
ExtensionObjectDefinition notification = notificationMessage.getBody();
222+
if (notification instanceof DataChangeNotification) {
223+
logger.trace("Found a Data Change Notification");
224+
DataChangeNotification data = (DataChangeNotification) notification;
225+
if (!data.getMonitoredItems().isEmpty()) {
226+
onMonitoredValue(data.getMonitoredItems());
227+
}
228+
} else if (notification instanceof EventNotificationList) {
229+
logger.trace("Found a Event Notification");
230+
EventNotificationList data = (EventNotificationList) notification;
231+
if (!data.getEvents().isEmpty()) {
232+
onEventNotification(data.getEvents());
233+
}
234+
} else {
235+
logger.warn("Unsupported Notification type {}", notification.getClass().getName());
235236
}
236-
} else {
237-
logger.warn("Unsupported Notification type {}", notification.getClass().getName());
238237
}
239238
}
240239
}).whenComplete((result, error) -> {

0 commit comments

Comments
 (0)