FlowLogicRefFactoryImpl.createForRpc
throws misleading error if no applicable FlowLogic
constructors are found
#6948
Labels
FlowLogicRefFactoryImpl.createForRpc
throws misleading error if no applicable FlowLogic
constructors are found
#6948
Hi R3.
I recently encountered the error
net.corda.core.flows.IllegalFlowLogicException: A FlowLogicRef cannot be constructed for FlowLogic of type com.deondigital.cordapp.flows.ExecuteOperationsFlow: due to ambiguous match against the constructors: [...]
Turns out that you get this error not when there are in fact multiple matching constructors, but when there are none.
Luckily the extra logging will tell you as much, but the exception itself is misleading.
To see why:
FlowLogicRefFactoryImpl.createForRpc
findContructor
in a try/catchIllegalArgumentException
is caught, then it throws the above errorLet's explore in which cases
findConstructor
might throwIllegalArgumentException
.findConstructor
first triesfindConstructorDirectMatch
.IllegalArgumentException
, a log message is produced, but the exception is swallowed.findConstructor
never throwsIllegalArgumentException
because offindConstructorDirectMatch
Then
findConstructorCheckDefaultParams
is called. Let's explore when it might throwIllegalArgumentException
.Looking at its definition, it's not immediately clear that it could throw an
IllegalArgumentException
, (except from a descendant caller, given thatIllegalArgumentException
is a very broadly used exception).However, if you look closer you see that it can throw an
IllegalFlowLogicException
which is a subclass ofIllegalArgumentException
Let's consider why and what happens if it throws
IllegalFlowLogicException
.createForRPC
which proceeds to ignore the message and throw a newIllegalFlowLogicException
with the message that there is an ambiguous match.However, in fact the only way you could get an
IllegalArgumentException
here is if there is no match, because any ambiguous match error would have been swallowed infindConstructor
.If/when you attempt to resolve this issue, my recommendation would be to not abuse such general exception classes as
IllegalArgumentExcpetion
to communicate errors that are related to your domain logic.In fact, depending on the usage patterns of the functions, you could conceivable throw away some of the exception handling here in favor of returning collections and then only throwing an exception in
createForRpc
depending on the size of the computed collection of constructors.The text was updated successfully, but these errors were encountered: