KryoException when wrong amount entered


(yassine) #1

Hello,

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:
GET
Path(“pay/{peerName}/{amount}”)
public String pay(@PathParam(“peerName”) String peerName, PathParam(“amount”) int quantity) {
System.out.println(“starting”);

    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) {
        e.printStackTrace();
        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 client.run - AMQ214000: Failed to call onMessage
com.esotericsoftware.kryo.KryoException: Buffer underflow.
Serialization trace:
value (rx.Notification)
at com.esotericsoftware.kryo.io.Input.require(Input.java:199) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.io.Input.readAscii_slow(Input.java:616) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.io.Input.readAscii(Input.java:594) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.io.Input.readString(Input.java:472) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:150) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:133) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:693) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:118) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:540) ~[kryo-4.0.0.jar:?]
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813) ~[kryo-4.0.0.jar:?]
at net.corda.core.serialization.ImmutableClassSerializer.read(Kryo.kt:193) ~[core-0.8.jar:?]
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:813) ~[kryo-4.0.0.jar:?]
at net.corda.core.serialization.KryoKt.deserialize(Kryo.kt:86) ~[core-0.8.jar:?]
at net.corda.node.services.messaging.CordaRPCClientImpl.deserialize(CordaRPCClientImpl.kt:108) ~[node-0.8.jar:?]
at net.corda.node.services.messaging.CordaRPCClientImpl.access$deserialize(CordaRPCClientImpl.kt:73) ~[node-0.8.jar:?]
at net.corda.node.services.messaging.CordaRPCClientImpl$QueuedObservable.deliver(CordaRPCClientImpl.kt:307) ~[node-0.8.jar:?]
at net.corda.node.services.messaging.CordaRPCClientImpl$QueuedObservable.access$deliver(CordaRPCClientImpl.kt:274) ~[node-0.8.jar:?]
at net.corda.node.services.messaging.CordaRPCClientImpl$QueuedObservable$consumer$2.onMessage(CordaRPCClientImpl.kt:284) ~[node-0.8.jar:?]
at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:1001) ~[artemis-core-client-1.5.1.jar:1.5.1]
at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl.access$400(ClientConsumerImpl.java:49) ~[artemis-core-client-1.5.1.jar:1.5.1]
at org.apache.activemq.artemis.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:1124) [artemis-core-client-1.5.1.jar:1.5.1]
at org.apache.activemq.artemis.utils.OrderedExecutorFactory$OrderedExecutor$ExecutorTask.run(OrderedExecutorFactory.java:101) [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$Worker.run(Unknown Source) [?:1.8.0_121]
at java.lang.Thread.run(Unknown 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.