0

I am trying to pass IOUFlowIssueTest but gives me the error that MockNetwork is not initialized whereas it's initialized.

This is on Corda 4.0.

class IOUIssueFlowTests {
    lateinit var mockNetwork: MockNetwork
    lateinit var a: StartedMockNode
    lateinit var b: StartedMockNode

    @Before
    fun setup() {
        mockNetwork = MockNetwork(listOf("net.corda.training"),
                notarySpecs = listOf(MockNetworkNotarySpec(CordaX500Name("Notary","London","GB"))))
        a = mockNetwork.createNode(MockNodeParameters())
        b = mockNetwork.createNode(MockNodeParameters())
        val startedNodes = arrayListOf(a, b)
        startedNodes.forEach { it.registerInitiatedFlow(IOUIssueFlowResponder::class.java) }
        mockNetwork.runNetwork()
    }
    @After
    fun tearDown() {
        mockNetwork.stopNodes()
    }

This is the error -

kotlin.UninitializedPropertyAccessException: lateinit property mockNetwork has not been initialized

Tim
  • 41,901
  • 18
  • 127
  • 145
  • Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – EpicPandaForce May 20 '19 at 13:25
  • can we see the stacktrace? I want to know which line it hits when it complains about it not being initialised. – Dan Newton May 20 '19 at 14:13
  • @DanNewton It hits the error at - mockNetwork.stopNodes() – lifelonglearner_rohit May 21 '19 at 06:43
  • is the `@Before`/`setup` function being triggered? Since it is set there, so the only way it can fail is if that the `setup` function is not being triggered. – Dan Newton May 21 '19 at 08:48
  • here it is - @Before fun setup() { mockNetwork = MockNetwork(listOf("net.corda.training"), notarySpecs = listOf(MockNetworkNotarySpec(CordaX500Name("Notary","London","GB")))) – lifelonglearner_rohit May 21 '19 at 10:15

1 Answers1

0

I have to guess a little: the only place I see which can cause an UninitializedPropertyAccessException is in your teardown method in case your MockNetwork constructor throws an exception.

Starting with Kotlin 1.2, you can check the initialisation state of a lateinit variable. So you can do the following:

@After
fun tearDown() {
    if(::mockNetwork.isInitialized) {
        mockNetwork.stopNodes()
    }
}
Dirk Bolte
  • 572
  • 4
  • 12