英文:
com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: java.io.StringReader, which is a closeable resource
问题
在我的Corda项目中,我有一个发起方流程和一个响应方流程。
在我的发起方流程中,我发送了一个字符串化的JSON,并期望从对方收到一个字符串作为确认。
String acknowledgment =
counterPartySession.sendAndReceive(String.class,jsonMessage.toString()).unwrap(data -> data);
而在对方流程中,我尝试检索消息并发送一个字符串作为响应。
JSONParser parser = new JSONParser();
String receivedMessage = session.receive(String.class).unwrap(data -> data);
JSONObject jsonObject = (JSONObject) parser.parse(receivedMessage);
String correlationId = (String) jsonObject.get("correlationId");
String response = "received message with correlationId: " + correlationId;
session.send(response);
但是在对方流程中,我遇到了以下堆栈跟踪错误:
com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: java.io.StringReader, which is a closeable resource, has been detected during flow checkpointing. Restoring such resources across node restarts is not supported. Make sure code accessing it is confined to a private method or the reference is nulled out.
Serialization trace:
zzReader (org.json.simple.parser.Yylex)
lexer (org.json.simple.parser.JSONParser)
dataObject (co.paralleluniverse.fibers.Stack)
stack (net.corda.node.services.statemachine.FlowStateMachineImpl)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:101) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:65) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.2.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeObject(ReplaceableObjectKryo.java:85) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:79) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:65) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.2.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeClassAndObject(ReplaceableObjectKryo.java:54) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.write(DefaultArraySerializers.java:361) ~[kryo-4.0.2.jar:?]
希望这可以帮助你解决问题。如果需要更多帮助,请告诉我。
英文:
I have a Intiator and a responder flow in my corda project.
I am sending a stringified json in my Initiator flow and expecting a string as acknowledgement from counterparty.
String acknowledgment =
counterPartySession.sendAndReceive(String.class,jsonMessage.toString()).unwrap(data -> data);
And in the counter party flow I am trying to retrieve the message and send a string as response.
JSONParser parser = new JSONParser();
String receivedMessage = session.receive(String.class).unwrap(data -> data);
JSONObject jsonObject = (JSONObject) parser.parse(receivedMessage);
String correlationId = (String) jsonObject.get("correlationId");
String response = "received message with correlationId: "+correlationId;
session.send(response);
but In the counter party flow I am getting an error with below stack trace.
com.esotericsoftware.kryo.KryoException: java.lang.UnsupportedOperationException: java.io.StringReader, which is a closeable resource, has been detected during flow checkpointing. Restoring such resources across node restarts is not supported. Make sure code accessing it is confined to a private method or the reference is nulled out.
Serialization trace:
zzReader (org.json.simple.parser.Yylex)
lexer (org.json.simple.parser.JSONParser)
dataObject (co.paralleluniverse.fibers.Stack)
stack (net.corda.node.services.statemachine.FlowStateMachineImpl)
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:101) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:65) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.2.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeObject(ReplaceableObjectKryo.java:85) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at com.esotericsoftware.kryo.serializers.ObjectField.write(ObjectField.java:79) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.serializers.CompatibleFieldSerializer.write(CompatibleFieldSerializer.java:65) ~[kryo-4.0.2.jar:?]
at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:575) ~[kryo-4.0.2.jar:?]
at co.paralleluniverse.io.serialization.kryo.ReplaceableObjectKryo.writeClassAndObject(ReplaceableObjectKryo.java:54) ~[quasar-core-0.7.10-jdk8.jar:0.7.10]
at com.esotericsoftware.kryo.serializers.DefaultArraySerializers$ObjectArraySerializer.write(DefaultArraySerializers.java:361) ~[kryo-4.0.2.jar:?]
答案1
得分: 2
当一个流程"checkpoints"时,它会序列化当前的执行堆栈。
错误提示说"java.io.StringReader"不能被序列化,因为它是可关闭的。你应该将这段代码放在一个单独的方法中,该方法不带有"@Suspendable"注解,或者更好的方法是将其放在一个"CordaService"内部。
英文:
When a flow checkpoints
, it serializes the current execution stack.
The error says java.io.StringReader
, cannot be serialized since it is closable. You should put the piece of code in a separate method, that is not annotated with @Suspendable
or a better way would be to put it inside a CordaService
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论