BrowseAsyncExample fails to complete due to java.util.concurrent.ExecutionException: java.lang.NullPointerException
See original GitHub issueDescribe the bug I’m using the code from browse example (https://github.com/eclipse/milo/blob/master/milo-examples/client-examples/src/main/java/org/eclipse/milo/examples/client/BrowseAsyncExample.java) on a test copy of a production OPC-UA server.
The problem is when try to run it i get the following error:
java.util.concurrent.ExecutionException: java.lang.NullPointerException at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:395) at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1999) … Caused by: java.lang.NullPointerException at java.base/java.util.Collections.addAll(Collections.java:5451) at org.eclipse.milo.opcua.sdk.client.BrowseHelper.maybeBrowseNext(BrowseHelper.java:90) at org.eclipse.milo.opcua.sdk.client.BrowseHelper.lambda$browse$1(BrowseHelper.java:78) at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1072) at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506) at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073) at org.eclipse.milo.opcua.stack.client.UaStackClient.lambda$deliverResponse$5(UaStackClient.java:256) at org.eclipse.milo.opcua.stack.core.util.ExecutionQueue$Task.run(ExecutionQueue.java:119) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) … 1 more
The exception happens when I try to call browseRecursive(client, tree).get()
.
public void run(OpcUaClient client, CompletableFuture<OpcUaClient> future) throws Exception {
// synchronous connect
client.connect().get();
// start browsing at root folder
UaNode rootNode = client.getAddressSpace().getNode(Identifiers.RootFolder);
Tree<UaNode> tree = new Tree<>(rootNode);
long startTime = System.nanoTime();
browseRecursive(client, tree).get(); <--- This line result in the Exception.
This is a result from the BrowseHelper. When you reach a “leaf” in the browsing of the nodes.
The result.getReferences()
is null
in my case when nextContinuationPoint.isNull() == true
.
The null
is added to the references
list which is passed to the completableFuture.
private static CompletableFuture<List<ReferenceDescription>> maybeBrowseNext(
UaStackClient client,
OpcUaSession session,
List<ReferenceDescription> references,
BrowseResult result
) {
if (result.getStatusCode().isGood()) {
Collections.addAll(references, result.getReferences()); < -- result.getReferences() == null when nextContinuationPoint.isNull() == true.
ByteString nextContinuationPoint = result.getContinuationPoint();
if (nextContinuationPoint == null || nextContinuationPoint.isNull()) {
return CompletableFuture.completedFuture(references); <-- The null is passed to the completableFuture
} else {
return browseNext(client, session, nextContinuationPoint, references);
}
} else {
return CompletableFuture.completedFuture(references);
}
}
Expected behavior I have tested some and made a test code with a null check. This seem to work in my case. But I OPC-UA noob and don’t have the whole picture.
private static CompletableFuture<List<ReferenceDescription>> maybeBrowseNext(
UaStackClient client,
OpcUaSession session,
List<ReferenceDescription> references,
BrowseResult result
) {
if (result.getStatusCode().isGood()) {
if (result.getReferences() != null) {
Collections.addAll(references, result.getReferences());
}
ByteString nextContinuationPoint = result.getContinuationPoint();
if (nextContinuationPoint == null || nextContinuationPoint.isNull()) {
return CompletableFuture.completedFuture(references);
} else {
return browseNext(client, session, nextContinuationPoint, references);
}
} else {
return CompletableFuture.completedFuture(references);
}
}
Logs and Packet Captures This is a printout of the response. BrowseResult(statusCode=StatusCode{name=Good, value=0x00000000, quality=good}, continuationPoint=ByteString{bytes=null}, references=null)], diagnosticInfos=[])
Additional context I’m using the 5.0.0 version of Milo.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
@MattiasBjorkman 0.5.1 has been released, containing this fix.
I tested your branch with the fix. It solved my problem. Thanks again.