The theoretically impossible has just happened: An IOException while reading to a ByteArrayInputStream.(it just happened)!

When trying to isolate some issues related to a Saga I’m trying to implement I have remade a simple project to try to isolate why I get the theoretically impossible situation:) Allard, could you help me out on this one? I can share/attach the project to the issue if needed.

Exception in thread “main” org.axonframework.serializer.SerializationException: The theoretically impossible has just happened: An IOException while reading to a ByteArrayInputStream.
at org.axonframework.serializer.JavaSerializer.deserialize(JavaSerializer.java:98)
at org.axonframework.saga.repository.mongo.SagaEntry.getSaga(SagaEntry.java:94)
at org.axonframework.saga.repository.mongo.MongoSagaRepository.load(MongoSagaRepository.java:66)
at org.axonframework.saga.AbstractSagaManager.loadAndInvoke(AbstractSagaManager.java:240)
at org.axonframework.saga.AbstractSagaManager.invokeExistingSagas(AbstractSagaManager.java:135)
at org.axonframework.saga.AbstractSagaManager.handle(AbstractSagaManager.java:106)
at org.axonframework.eventhandling.SimpleCluster.doPublish(SimpleCluster.java:65)
at org.axonframework.eventhandling.AbstractCluster.publish(AbstractCluster.java:77)
at org.axonframework.eventhandling.ClusteringEventBus$SimpleEventBusTerminal.publish(ClusteringEventBus.java:132)
at org.axonframework.eventhandling.ClusteringEventBus.publish(ClusteringEventBus.java:94)
at com.navarsete.stand012.dummy.RunSupplierSaga.main(RunSupplierSaga.java:25)
Caused by: java.io.InvalidClassException: com.navarsete.stand012.dummy.SupplierSaga; local class incompatible: stream classdesc serialVersionUID = 1975893487230154183, local class serialVersionUID = -3893561804673049114
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:617)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1622)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1517)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1771)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1350)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:370)
at org.axonframework.serializer.JavaSerializer.deserialize(JavaSerializer.java:94)

DummyAxon.tar.gz (6.76 KB)

Hi Allard!

I simply couldn’t go to bed without looking more into this. When I removed the saga-repository=“mongoSagaRepository” from the defintion of the saga-manager (meaning it will default to the in-memory manager), then I don’t get the error mentioned below. Also, without the saga-repository set on the bean, then the CommandGateway IS injected into the saga, otherwise it’s not! (meaning ending with NPE in the saga).

I really need a second pair of eyes on this one, since this is far outside my comfort zone :slight_smile:

Regards,
Viggo

Perhaps you have two different versions of the SupplierSaga class on your classpath which have a different value for the serialVersionUID field?

Srdan

Hmm,how would I check it? Seems to only be a problem when I run with a mongo repository also,not with in-memory, but I don't know.

Perhaps your project setup has two suppliersagaS on the classpath? If your project is within eclipse I’m sure there’s a way you can see how many classes on the classpath have that name (Ctrl+Shit+T).

Srdan

Hi VIggo,

the problem is that you have a serialized version of a class that has been modified since you stored it. This happens when you don’t specify a Serializer to use. For backwards compatibility reasons, the default serializer is the JavaSerializer. It uses Java’s own serialization mechanism. You probably haven’t specified a serialVersionUid in your Saga. If you do (and set it to 1975893487230154183, it’s likely to work again. Unless you made a breaking change.
My advice would be to use the XStream serializer. It’s more tolerant of class changes.

If you don’t specify a repository, and store everything in-memory, it works because it doesn’t need to do any serialization.

Cheers,

Allard

Hi Allard!

Tonight I had time to try your suggestion, I added the serialVersionUid and also tried to add the use of XStream serializer, but the code is still not very happy with me:(

Output:

Exception in thread “main” com.thoughtworks.xstream.io.StreamException: : only whitespace content allowed before start tag and not \ufffd (position: START_DOCUMENT seen \ufffd… @1:1)
at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:124)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.readRealEvent(AbstractPullReader.java:148)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.readEvent(AbstractPullReader.java:141)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.move(AbstractPullReader.java:118)
at com.thoughtworks.xstream.io.xml.AbstractPullReader.moveDown(AbstractPullReader.java:103)
at com.thoughtworks.xstream.io.xml.XppReader.(XppReader.java:63)
at com.thoughtworks.xstream.io.xml.AbstractXppDriver.createReader(AbstractXppDriver.java:54)
at org.axonframework.serializer.xml.CompactDriver.createReader(CompactDriver.java:48)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:1012)
at org.axonframework.serializer.xml.XStreamSerializer.doDeserialize(XStreamSerializer.java:142)
at org.axonframework.serializer.AbstractXStreamSerializer.deserialize(AbstractXStreamSerializer.java:225)
at org.axonframework.saga.repository.mongo.SagaEntry.getSaga(SagaEntry.java:94)
at org.axonframework.saga.repository.mongo.MongoSagaRepository.load(MongoSagaRepository.java:66)
at org.axonframework.saga.AbstractSagaManager.loadAndInvoke(AbstractSagaManager.java:240)
at org.axonframework.saga.AbstractSagaManager.invokeExistingSagas(AbstractSagaManager.java:135)
at org.axonframework.saga.AbstractSagaManager.handle(AbstractSagaManager.java:106)
at org.axonframework.eventhandling.SimpleCluster.doPublish(SimpleCluster.java:65)
at org.axonframework.eventhandling.AbstractCluster.publish(AbstractCluster.java:77)
at org.axonframework.eventhandling.ClusteringEventBus$SimpleEventBusTerminal.publish(ClusteringEventBus.java:132)
at org.axonframework.eventhandling.ClusteringEventBus.publish(ClusteringEventBus.java:94)
at com.navarsete.stand012.supplier.RunSupplierSaga.main(RunSupplierSaga.java:30)
Caused by: org.xmlpull.v1.XmlPullParserException: only whitespace content allowed before start tag and not \ufffd (position: START_DOCUMENT seen \ufffd… @1:1)
at org.xmlpull.mxp1.MXParser.parseProlog(MXParser.java:1519)
at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1395)
at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)
at com.thoughtworks.xstream.io.xml.XppReader.pullNextEvent(XppReader.java:109)

Here is my spring-context.xml:

<axon:annotation-config />

<context:annotation-config />

<axon:event-sourcing-repository id=“purchaseOrderRepository”
aggregate-type=“com.navarsete.stand012.wholesaler.PurchaseOrder”
event-bus=“eventBus”
event-store=“eventStore”

</axon:event-sourcing-repository>

<axon:aggregate-command-handler id=“purchaseOrderCommandHandler”
aggregate-type=“com.navarsete.stand012.wholesaler.PurchaseOrder”
repository=“purchaseOrderRepository”
command-bus=“commandBus”
/>

<axon:event-sourcing-repository id=“transportOrderRepository”
aggregate-type=“com.navarsete.stand012.transporter.TransportOrder”
event-bus=“eventBus”
event-store=“eventStore”

</axon:event-sourcing-repository>

<axon:aggregate-command-handler id=“transportOrderCommandHandler”
aggregate-type=“com.navarsete.stand012.transporter.TransportOrder”
repository=“transportOrderRepository”
command-bus=“commandBus”
/>

<axon:event-sourcing-repository id=“supplierOrderRepository”
aggregate-type=“com.navarsete.stand012.supplier.SupplierOrder”
event-bus=“eventBus”
event-store=“eventStore”

</axon:event-sourcing-repository>

<axon:aggregate-command-handler id=“supplierOrderCommandHandler”
aggregate-type=“com.navarsete.stand012.supplier.SupplierOrder”
repository=“supplierOrderRepository”
command-bus=“commandBus”
/>

<axon:saga-manager id=“supplierSagaManager” saga-repository=“mongoSagaRepository” event-bus=“eventBus” >

axon:types
com.navarsete.stand012.supplier.SupplierSaga
</axon:types>
</axon:saga-manager>

<axon:event-bus id=“eventBus”/>
<axon:command-bus id=“commandBus”/>









I might send/add more if you need to look into this!

Regards,
Viggo

I see that the issue I have with the “only whitespace content allowed…” is also discussed (but not concluded) in this thread: https://groups.google.com/forum/#!msg/axonframework/A8l0HSs0yV0/cGAYYVcqfi0J

I’ve tried to use the MongoSagaRepository with the ToDoSaga in Axon Quickstart, and it works. I then tried to copy the ToDoSaga (and dependent classes) into my project and run it there to see if it was any of my dependencies (i.e more current Spring version…) that made my own Saga fail, but the ToDoSaga still worked. SO, I think this must be related to some issues in my own classes, so I’ll try strip down my own project to make it even simpler to see what can cause my issues. I’ll let you know if I need any assistance, but since the Axon Quickstart ToDoSaga works, it should be a good example to follow to fix my own:)

Cheers :slight_smile:

Hi Viggo,

have you cleaned your DB in between serializer changes? If you’re trying to load Java-serialized data back in using UTF-8, you can get \ufffd characters, which are replacement characters. It’s used when reading a character not representable in unicode.
This could also have been the issue while you were using the Java serializer. Perhaps there was serialized data of another version of the class in there.

Hope this helps.
Cheers,

Allard

Hi Allard:)

Seems like all problems vanished as soon as I dropped the database! Thanks a lot :slight_smile: