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.

`java.lang.NullPointerException: null` when suspending despite `@Suspendable`

See original GitHub issue

See https://github.com/corda/cordapp-example/tree/joel-bug-branch.

The flow is defined in Java as follows:

package com.example.flow;

import co.paralleluniverse.fibers.Suspendable;
import com.google.common.collect.ImmutableList;
import kotlin.Triple;
import net.corda.core.flows.*;
import net.corda.core.identity.Party;

import java.util.List;

public class ExampleFlow {
    @InitiatingFlow
    @StartableByRPC
    public static class Initiator extends FlowLogic<Void> {
        private final Party otherParty;

        public Initiator(Party otherParty) {
            this.otherParty = otherParty;
        }

        @Suspendable
        @Override
        public Void call() throws FlowException {
            FlowSession otherPartySession = initiateFlow(otherParty);
            List<FlowSession> sessions = ImmutableList.of(otherPartySession);
            sessions.forEach( it -> sendAMessage(it, new Triple("a", "b", "c")));
            return null;
        }
    }

    @InitiatedBy(Initiator.class)
    public static class Acceptor extends FlowLogic<Void> {

        private final FlowSession otherPartyFlow;

        public Acceptor(FlowSession otherPartyFlow) {
            this.otherPartyFlow = otherPartyFlow;
        }

        @Suspendable
        @Override
        public Void call() throws FlowException {
            otherPartyFlow.receive(Triple.class).unwrap(it -> { return it; });
            return null;
        }
    }

    @Suspendable
    private static Void sendAMessage(FlowSession session, Triple t) {
        session.send(t);
        return null;
    }
}

Running it (e.g. by running the flow tests here: https://github.com/corda/cordapp-example/blob/joel-bug-branch/java-source/src/test/java/com/example/flow/IOUFlowTests.java) gives the following exception:

java.lang.NullPointerException: null
    at net.corda.node.services.statemachine.FlowStateMachineImpl.suspend(FlowStateMachineImpl.kt:514) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.sendInternal(FlowStateMachineImpl.kt:370) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.initiateSession(FlowStateMachineImpl.kt:434) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.initiateSession$default(FlowStateMachineImpl.kt:423) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.send(FlowStateMachineImpl.kt:246) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowSessionImpl.send(FlowSessionImpl.kt:52) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowSessionImpl.send(FlowSessionImpl.kt:56) ~[corda-node-3.2-corda.jar:?]
    at com.example.flow.ExampleFlow.sendAMessage(ExampleFlow.java:50) ~[classes/:?]
    at com.example.flow.ExampleFlow.access$000(ExampleFlow.java:11) ~[classes/:?]
    at com.example.flow.ExampleFlow$Initiator.lambda$call$0(ExampleFlow.java:26) ~[classes/:?]
    at com.google.common.collect.ImmutableList.forEach(ImmutableList.java:408) ~[guava-21.0.jar:?]
    at com.example.flow.ExampleFlow$Initiator.call(ExampleFlow.java:26) ~[classes/:?]
    at com.example.flow.ExampleFlow$Initiator.call(ExampleFlow.java:12) ~[classes/:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:96) [corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) [corda-node-3.2-corda.jar:?]
    at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_171]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
    at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.2-corda.jar:?]
[WARN ] 17:03:28,364 [Mock network] (StateMachineManagerImpl.kt:79) flow.[0f10b2ef-f456-4e28-9998-1b2a403c6caf].uncaughtException - Caught exception from flow {}
java.lang.IllegalStateException: Was expecting to find transaction set on current strand: Fiber@10000001:[0f10b2ef-f456-4e28-9998-1b2a403c6caf][task: co.paralleluniverse.fibers.RunnableFiberTask@12a75b63(Fiber@10000001), target: null, scheduler: net.corda.node.services.statemachine.StateMachineManagerImpl$FiberScheduler@3facca05]
    at net.corda.nodeapi.internal.persistence.DatabaseTransactionKt.getContextTransaction(DatabaseTransaction.kt:14) ~[corda-node-api-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.rollbackTransaction$node(FlowStateMachineImpl.kt:151) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.StateMachineManagerImpl$initFiber$3.invoke(StateMachineManagerImpl.kt:460) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.StateMachineManagerImpl$initFiber$3.invoke(StateMachineManagerImpl.kt:63) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.processException(FlowStateMachineImpl.kt:131) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:112) ~[corda-node-3.2-corda.jar:?]
    at net.corda.node.services.statemachine.FlowStateMachineImpl.run(FlowStateMachineImpl.kt:44) ~[corda-node-3.2-corda.jar:?]
    at co.paralleluniverse.fibers.Fiber.run1(Fiber.java:1092) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.Fiber.exec(Fiber.java:788) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.doExec(RunnableFiberTask.java:100) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at co.paralleluniverse.fibers.RunnableFiberTask.run(RunnableFiberTask.java:91) [quasar-core-0.7.9-jdk8.jar:0.7.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_171]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_171]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_171]
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [?:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_171]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_171]
    at net.corda.node.utilities.AffinityExecutor$ServiceAffinityExecutor$1$thread$1.run(AffinityExecutor.kt:62) [corda-node-3.2-corda.jar:?]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
keykey7commented, Mar 19, 2019

I also face NPEs on a pure-java dapp during the suspend.

java.lang.NullPointerException
	at net.corda.node.services.statemachine.FlowStateMachineImpl.suspend(FlowStateMachineImpl.kt:380)
	at net.corda.node.services.statemachine.FlowSessionImpl.send(FlowSessionImpl.kt:78)
	at net.corda.node.services.statemachine.FlowSessionImpl.send(FlowSessionImpl.kt:82)

It’s not the first suspend within this flow. I can only reproduce it on a real multinode setup, but not with a multinode mock network. -Dco.paralleluniverse.fibers.verifyInstrumentation=true doesn’t complain nor does flowStackSnapshot() reveal any unexpected insights: there are no lambdas, unserializable classes, or alike in any frame. @lolo8304’s kotlin-project-hack didn’t help either. Any ideas on how to further debug such a Fiber issue?

0reactions
davidrapacchialecommented, May 20, 2020

Closing this issue as it is related to an old version of the software. Either not relevant any longer, or fixed elsewhere. Please do reopen if still relevant.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Suspended exception NullPointerException (Full error ...
It appears, sheet.SIZE throws exception; as you are invoking method on a null object. Take care of Object creation, initialization before you ...
Read more >
How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >
How to deal with NullPointerException in Java with Examples
NullPointerException has outlined scenario when it could occur: 1) When you call the instance method on a null object. you won't get a...
Read more >
EMF » Null pointer exception in ... - Eclipse Community Forums
Hi, I have been struggling for the past couple of days with an EMF problem. I am using EMF UML2 4.0 models that...
Read more >
NullPointerException on compiling suspend inline fun with ...
no matter what I do. Adding noinline can avoid that. ... The function foo of the example above is in a inline class...
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