From ae01d658b6ace6de4774a343c0bb5b459b64c7f4 Mon Sep 17 00:00:00 2001
From: Shams Asari <shams.asari@r3.com>
Date: Thu, 13 Jul 2017 17:09:15 +0100
Subject: [PATCH] Renamed FlowSessionException to UnexpectedFlowEndException

---
 .../kotlin/net/corda/core/flows/FlowException.kt     |  2 +-
 .../net/corda/core/flows/ContractUpgradeFlowTest.kt  |  4 ++--
 .../services/statemachine/FlowStateMachineImpl.kt    |  6 +++---
 .../node/services/statemachine/SessionMessage.kt     |  4 ++--
 .../node/services/statemachine/FlowFrameworkTests.kt | 12 ++++++------
 5 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/core/src/main/kotlin/net/corda/core/flows/FlowException.kt b/core/src/main/kotlin/net/corda/core/flows/FlowException.kt
index e527f22c55..4e20320883 100644
--- a/core/src/main/kotlin/net/corda/core/flows/FlowException.kt
+++ b/core/src/main/kotlin/net/corda/core/flows/FlowException.kt
@@ -25,6 +25,6 @@ open class FlowException(message: String?, cause: Throwable?) : CordaException(m
  * that we were not expecting), or the other side had an internal error, or the other side terminated when we
  * were waiting for a response.
  */
-class FlowSessionException(message: String?, cause: Throwable?) : CordaRuntimeException(message, cause) {
+class UnexpectedFlowEndException(message: String?, cause: Throwable?) : CordaRuntimeException(message, cause) {
     constructor(msg: String) : this(msg, null)
 }
\ No newline at end of file
diff --git a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt
index 889d392ff2..000e81afcc 100644
--- a/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt
+++ b/core/src/test/kotlin/net/corda/core/flows/ContractUpgradeFlowTest.kt
@@ -71,7 +71,7 @@ class ContractUpgradeFlowTest {
         // The request is expected to be rejected because party B hasn't authorised the upgrade yet.
         val rejectedFuture = a.services.startFlow(ContractUpgradeFlow(atx!!.tx.outRef(0), DummyContractV2::class.java)).resultFuture
         mockNet.runNetwork()
-        assertFailsWith(FlowSessionException::class) { rejectedFuture.getOrThrow() }
+        assertFailsWith(UnexpectedFlowEndException::class) { rejectedFuture.getOrThrow() }
 
         // Party B authorise the contract state upgrade.
         b.services.vaultService.authoriseContractUpgrade(btx!!.tx.outRef<ContractState>(0), DummyContractV2::class.java)
@@ -141,7 +141,7 @@ class ContractUpgradeFlowTest {
                     DummyContractV2::class.java).returnValue
 
             mockNet.runNetwork()
-            assertFailsWith(FlowSessionException::class) { rejectedFuture.getOrThrow() }
+            assertFailsWith(UnexpectedFlowEndException::class) { rejectedFuture.getOrThrow() }
 
             // Party B authorise the contract state upgrade.
             rpcB.authoriseContractUpgrade(btx!!.tx.outRef<ContractState>(0), DummyContractV2::class.java)
diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt
index 14f4013ed4..c695424938 100644
--- a/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt
+++ b/node/src/main/kotlin/net/corda/node/services/statemachine/FlowStateMachineImpl.kt
@@ -255,7 +255,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
             state = FlowSessionState.Initiated(peerParty, sessionInitResponse.initiatedSessionId)
         } else {
             sessionInitResponse as SessionReject
-            throw FlowSessionException("Party ${state.sendToParty} rejected session request: ${sessionInitResponse.errorMessage}")
+            throw UnexpectedFlowEndException("Party ${state.sendToParty} rejected session request: ${sessionInitResponse.errorMessage}")
         }
     }
 
@@ -357,7 +357,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
                 session.erroredEnd(message)
             } else {
                 val expectedType = receiveRequest.userReceiveType?.name ?: receiveType.simpleName
-                throw FlowSessionException("Counterparty flow on ${session.state.sendToParty} has completed without " +
+                throw UnexpectedFlowEndException("Counterparty flow on ${session.state.sendToParty} has completed without " +
                         "sending a $expectedType")
             }
         } else {
@@ -371,7 +371,7 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
             (end.errorResponse as java.lang.Throwable).fillInStackTrace()
             throw end.errorResponse
         } else {
-            throw FlowSessionException("Counterparty flow on ${state.sendToParty} had an internal error and has terminated")
+            throw UnexpectedFlowEndException("Counterparty flow on ${state.sendToParty} had an internal error and has terminated")
         }
     }
 
diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt
index 9f35c9eace..8b25d0b0b7 100644
--- a/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt
+++ b/node/src/main/kotlin/net/corda/node/services/statemachine/SessionMessage.kt
@@ -2,7 +2,7 @@ package net.corda.node.services.statemachine
 
 import net.corda.core.flows.FlowException
 import net.corda.core.flows.FlowLogic
-import net.corda.core.flows.FlowSessionException
+import net.corda.core.flows.UnexpectedFlowEndException
 import net.corda.core.identity.Party
 import net.corda.core.serialization.CordaSerializable
 import net.corda.core.utilities.UntrustworthyData
@@ -45,7 +45,7 @@ fun <T> ReceivedSessionMessage<SessionData>.checkPayloadIs(type: Class<T>): Untr
     if (type.isInstance(message.payload)) {
         return UntrustworthyData(type.cast(message.payload))
     } else {
-        throw FlowSessionException("We were expecting a ${type.name} from $sender but we instead got a " +
+        throw UnexpectedFlowEndException("We were expecting a ${type.name} from $sender but we instead got a " +
                 "${message.payload.javaClass.name} (${message.payload})")
     }
 }
diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt
index 7526d81740..b4c28dc7c4 100644
--- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt
+++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowFrameworkTests.kt
@@ -377,7 +377,7 @@ class FlowFrameworkTests {
         node2.registerFlowFactory(ReceiveFlow::class) { NoOpFlow() }
         val resultFuture = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
         mockNet.runNetwork()
-        assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
+        assertThatExceptionOfType(UnexpectedFlowEndException::class.java).isThrownBy {
             resultFuture.getOrThrow()
         }.withMessageContaining(String::class.java.name)  // Make sure the exception message mentions the type the flow was expecting to receive
     }
@@ -400,7 +400,7 @@ class FlowFrameworkTests {
                 Notification.createOnError(erroringFlowFuture.get().exceptionThrown)
         )
 
-        val receiveFlowException = assertFailsWith(FlowSessionException::class) {
+        val receiveFlowException = assertFailsWith(UnexpectedFlowEndException::class) {
             receiveFlowResult.getOrThrow()
         }
         assertThat(receiveFlowException.message).doesNotContain("evil bug!")
@@ -486,7 +486,7 @@ class FlowFrameworkTests {
             node1Fiber.resultFuture.getOrThrow()
         }
         val node2ResultFuture = node2Fiber.getOrThrow().resultFuture
-        assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
+        assertThatExceptionOfType(UnexpectedFlowEndException::class.java).isThrownBy {
             node2ResultFuture.getOrThrow()
         }
 
@@ -539,7 +539,7 @@ class FlowFrameworkTests {
         node2.registerFlowFactory(ReceiveFlow::class) { SendFlow(NonSerialisableData(1), it) }
         val result = node1.services.startFlow(ReceiveFlow(node2.info.legalIdentity)).resultFuture
         mockNet.runNetwork()
-        assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
+        assertThatExceptionOfType(UnexpectedFlowEndException::class.java).isThrownBy {
             result.getOrThrow()
         }
     }
@@ -581,7 +581,7 @@ class FlowFrameworkTests {
         }
         val waiter = node2.services.startFlow(WaitingFlows.Waiter(stx, node1.info.legalIdentity)).resultFuture
         mockNet.runNetwork()
-        assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
+        assertThatExceptionOfType(UnexpectedFlowEndException::class.java).isThrownBy {
             waiter.getOrThrow()
         }
     }
@@ -643,7 +643,7 @@ class FlowFrameworkTests {
                 track = false)
         val result = node1.services.startFlow(UpgradedFlow(node2.info.legalIdentity)).resultFuture
         mockNet.runNetwork()
-        assertThatExceptionOfType(FlowSessionException::class.java).isThrownBy {
+        assertThatExceptionOfType(UnexpectedFlowEndException::class.java).isThrownBy {
             result.getOrThrow()
         }.withMessageContaining("Version")
     }