CORDA-3685: Prevent ServiceHub.signInitialTransaction from throwing undeclared checked exceptions. (#6111)

This commit is contained in:
Chris Rankin 2020-04-28 17:02:37 +01:00 committed by GitHub
parent 297e504740
commit 592d7238fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -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:

View File

@ -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)
}