question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BrowseAsyncExample fails to complete due to java.util.concurrent.ExecutionException: java.lang.NullPointerException

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinherroncommented, Sep 25, 2020

@MattiasBjorkman 0.5.1 has been released, containing this fix.

0reactions
MattiasBjorkmancommented, Sep 14, 2020

I tested your branch with the fix. It solved my problem. Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.util.concurrent.ExecutionException - Stack Overflow
This is fixed. If it could useful: The problem was with the way the variables were declared. I had to declare a class-level...
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
The NullPointerException occurs due to a situation in application code where an uninitialized object is attempted to be accessed or modified.
Read more >
How to resolve the java.lang.NullPointerException - Educative.io
NullPointerException is thrown when a reference variable is accessed (or de-referenced) and is not pointing to any object. This error can be resolved...
Read more >
Veridata 12.2.1.4 Jobs are failing with <OGGV-00212 ...
Using GoldenGate Veridata 12.2.1.4, Jobs are failing with Failed: java.util.concurrent.ExecutionException: java.lang.NullPointerException
Read more >
Gradle 7.2.0 causing APK build error com.android.tools.r8 ...
CompilationFailedException: Compilation failed to complete, ... java.lang.NullPointerException at java.base/java.util.concurrent.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found