mirror of
https://github.com/corda/corda.git
synced 2024-12-20 21:43:14 +00:00
CORDA-3685: Prevent ServiceHub.signInitialTransaction from throwing undeclared checked exceptions. (#6111)
This commit is contained in:
parent
297e504740
commit
592d7238fd
@ -77,7 +77,12 @@ fun <T : Any> deserialiseComponentGroup(componentGroups: List<ComponentGroup>,
|
||||
try {
|
||||
factory.deserialize(component, clazz.java, context)
|
||||
} catch (e: MissingAttachmentsException) {
|
||||
throw e
|
||||
/**
|
||||
* [ServiceHub.signInitialTransaction] forgets to declare that
|
||||
* it may throw any checked exceptions. Wrap this one inside
|
||||
* an unchecked version to avoid breaking Java CorDapps.
|
||||
*/
|
||||
throw MissingAttachmentsRuntimeException(e.ids, e.message, e)
|
||||
} catch (e: Exception) {
|
||||
throw TransactionDeserialisationException(groupEnum, internalIndex, e)
|
||||
}
|
||||
@ -88,7 +93,7 @@ fun <T : Any> deserialiseComponentGroup(componentGroups: List<ComponentGroup>,
|
||||
* Exception raised if an error was encountered while attempting to deserialise a component group in a transaction.
|
||||
*/
|
||||
class TransactionDeserialisationException(groupEnum: ComponentGroupEnum, index: Int, cause: Exception):
|
||||
Exception("Failed to deserialise group $groupEnum at index $index in transaction: ${cause.message}", cause)
|
||||
RuntimeException("Failed to deserialise group $groupEnum at index $index in transaction: ${cause.message}", cause)
|
||||
|
||||
/**
|
||||
* Method to deserialise Commands from its two groups:
|
||||
|
@ -0,0 +1,17 @@
|
||||
package net.corda.core.serialization
|
||||
|
||||
import net.corda.core.CordaRuntimeException
|
||||
import net.corda.core.KeepForDJVM
|
||||
import net.corda.core.node.services.AttachmentId
|
||||
|
||||
@KeepForDJVM
|
||||
@CordaSerializable
|
||||
class MissingAttachmentsRuntimeException(val ids: List<AttachmentId>, message: String?, cause: Throwable?)
|
||||
: CordaRuntimeException(message, cause) {
|
||||
|
||||
@Suppress("unused")
|
||||
constructor(ids: List<AttachmentId>, message: String?) : this(ids, message, null)
|
||||
|
||||
@Suppress("unused")
|
||||
constructor(ids: List<AttachmentId>) : this(ids, null, null)
|
||||
}
|
Loading…
Reference in New Issue
Block a user