KryoException when wrong amount entered

(yassine) #1


I am trying to build a RESTfull API on top of corda, so I cloned the Cordapp Template and started playing.
So I have this “pay” method:
public String pay(@PathParam(“peerName”) String peerName, PathParam(“amount”) int quantity) {

    Party party = findPeerByName(peerName);

    if (party == null) {
        return "Peer not found";
    try {
        System.out.println("Issuer: " + issuers.get(0));

        Amount<Issued<Currency>> amount = new Amount<>(quantity, new Issued<>(new PartyAndReference(issuers.get(0), OpaqueBytes.Companion.of((byte) 1)), ContractsDSL.USD));
        CashCommand.PayCash cash = new CashCommand.PayCash(amount, party);
        FlowHandle handle = services.startFlowDynamic(CashFlow.class, cash);

        handle.getProgress().subscribe(o -> System.out.println("done " + o));

        System.out.println("result " + handle.getReturnValue().get());

        return "issued ";
    } catch (Exception e) {
        return "err " + e.getMessage();


Whenever the arguments peer name and the amount are valid, everything works, but say when I enter an amount which the current node dosnt have, I get a weird non-instructive exception:

E 01:36:52 98 - AMQ214000: Failed to call onMessage
com.esotericsoftware.kryo.KryoException: Buffer underflow.
Serialization trace:
value (rx.Notification)
at ~[kryo-4.0.0.jar:?]
at ~[kryo-4.0.0.jar:?]
at ~[kryo-4.0.0.jar:?]
at ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.util.DefaultClassResolver.readName( ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass( ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.Kryo.readClass( ~[kryo-4.0.0.jar:?]
at ~[kryo-4.0.0.jar:?]
at ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.Kryo.readClassAndObject( ~[kryo-4.0.0.jar:?]
at ~[core-0.8.jar:?]
at com.esotericsoftware.kryo.Kryo.readClassAndObject( ~[kryo-4.0.0.jar:?]
at net.corda.core.serialization.KryoKt.deserialize(Kryo.kt:86) ~[core-0.8.jar:?]
at ~[node-0.8.jar:?]
at$deserialize(CordaRPCClientImpl.kt:73) ~[node-0.8.jar:?]
at$QueuedObservable.deliver(CordaRPCClientImpl.kt:307) ~[node-0.8.jar:?]
at$QueuedObservable.access$deliver(CordaRPCClientImpl.kt:274) ~[node-0.8.jar:?]
at$QueuedObservable$consumer$2.onMessage(CordaRPCClientImpl.kt:284) ~[node-0.8.jar:?]
at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl.callOnMessage( ~[artemis-core-client-1.5.1.jar:1.5.1]
at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl.access$400( ~[artemis-core-client-1.5.1.jar:1.5.1]
at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl$ [artemis-core-client-1.5.1.jar:1.5.1]
at org.apache.activemq.artemis.utils.OrderedExecutorFactory$OrderedExecutor$ [artemis-commons-1.5.1.jar:1.5.1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$ Source) [?:1.8.0_121]
at Source) [?:1.8.0_121]

I checked on both the node and the node web logs, and no further details appeared.

(Roger Willis) #2

Thanks for the heads up. Appreciate this is not an instructive error. I believe the issue is that Kryo doesn’t know how to serialise the exception which has been thrown @parkri. I believe if we whitelist the Exception class which is being thrown then this shall cease to be an issue. Cheers

(yassine) #3

Thank you for your reply, and yes I agree, and Im aware that you can whitelist a class in a plugin under the registerRPCKryoTypes method, I have had this exception before and did that, but in this situation I did not know which class i should be whitelisting, I tried to add the Exception class kryo.register(Exception.class,32); but still same error.

(Gary Rowe) #4

Although this isn’t necessarily the correct answer to the situation above, I did encounter a similar error when using the CordaClientRPC in version 2.0.0 to access nodeInfo.

ERROR 86562 --- [global-threads)] org.apache.activemq.artemis.core.client  : AMQ214000: Failed to call onMessage

com.esotericsoftware.kryo.KryoException: java.lang.IllegalArgumentException: Privacy salt should be 32 bytes.
Serialization trace:
legalIdentitiesAndCerts (net.corda.core.node.NodeInfo)
value (net.corda.core.utilities.Try$Success)

After some searching it came down to using an incompatible version of Google Guava: 21.0 or 22.0 were fine, but 23.0 gave the error.

Hope this helps someone.