mirror of
https://github.com/corda/corda.git
synced 2025-01-29 15:43:55 +00:00
Fix ClassNotFound handling (#5078)
This commit is contained in:
parent
268f6db430
commit
25f335861b
@ -27,6 +27,7 @@ import java.util.regex.Pattern
|
|||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.component1
|
import kotlin.collections.component1
|
||||||
import kotlin.collections.component2
|
import kotlin.collections.component2
|
||||||
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TransactionBuilder is a transaction class that's mutable (unlike the others which are all immutable). It is
|
* A TransactionBuilder is a transaction class that's mutable (unlike the others which are all immutable). It is
|
||||||
@ -169,6 +170,13 @@ open class TransactionBuilder(
|
|||||||
wireTx
|
wireTx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the first exception in the hierarchy that matches one of the [types].
|
||||||
|
private tailrec fun Throwable.rootClassNotFoundCause(vararg types: KClass<*>): Throwable = when {
|
||||||
|
this::class in types -> this
|
||||||
|
this.cause == null -> this
|
||||||
|
else -> this.cause!!.rootClassNotFoundCause(*types)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if a new dependency was successfully added.
|
* @return true if a new dependency was successfully added.
|
||||||
*/
|
*/
|
||||||
@ -178,7 +186,8 @@ open class TransactionBuilder(
|
|||||||
// The transaction verified successfully without adding any extra dependency.
|
// The transaction verified successfully without adding any extra dependency.
|
||||||
false
|
false
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
val rootError = e.rootCause
|
val rootError = e.rootClassNotFoundCause(ClassNotFoundException::class, NoClassDefFoundError::class)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
// Handle various exceptions that can be thrown during verification and drill down the wrappings.
|
// Handle various exceptions that can be thrown during verification and drill down the wrappings.
|
||||||
// Note: this is a best effort to preserve backwards compatibility.
|
// Note: this is a best effort to preserve backwards compatibility.
|
||||||
|
@ -23,10 +23,12 @@ internal inline fun <T> ifThrowsAppend(strToAppendFn: () -> String, block: () ->
|
|||||||
try {
|
try {
|
||||||
return block()
|
return block()
|
||||||
} catch (th: Throwable) {
|
} catch (th: Throwable) {
|
||||||
if (th is AMQPNotSerializableException) {
|
when (th) {
|
||||||
th.classHierarchy.add(strToAppendFn())
|
is AMQPNotSerializableException -> th.classHierarchy.add(strToAppendFn())
|
||||||
} else {
|
// Do not overwrite the message of these exceptions as it may be used.
|
||||||
th.setMessage("${strToAppendFn()} -> ${th.message}")
|
is ClassNotFoundException -> {}
|
||||||
|
is NoClassDefFoundError -> {}
|
||||||
|
else -> th.setMessage("${strToAppendFn()} -> ${th.message}")
|
||||||
}
|
}
|
||||||
throw th
|
throw th
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user