ConversionException during deserialization of externalizable object

78 views
Skip to first unread message

Vladislav Kalko

unread,
May 18, 2021, 2:49:43 PM5/18/21
to XStream User
Hello!
I noticed following issue while using XStream library bundled in Quarkus (tested using default version 1.4.14 and latest 1.4.17 added manually):

during deserialization of Externalizable object (of avro-generated class), which has field of type Long and value greated than 1073741823L following exception appears:

com.thoughtworks.xstream.converters.ConversionException: 
---- Debugging information ----
cause-exception     : java.lang.ClassCastException
cause-message       : class [B cannot be cast to class java.lang.Byte ([B and java.lang.Byte are in module java.base of loader 'bootstrap')
class               : org.acme.Entity
required-type       : org.acme.Entity
converter-type      : com.thoughtworks.xstream.converters.reflection.ExternalizableConverter
path                : /org.acme.Entity
line number         : 4
version             : 1.4.17
-------------------------------
If value of the field is 1073741823L and less, there is no error.

Just run MainTest in test/java/org/acme.

I will really appreciate any help and will glad to answer your questions and provide additional information if necessary.

Jörg Schaible

unread,
May 18, 2021, 6:24:52 PM5/18/21
to XStream User
Hi,

On Tuersday, 18. May 2021, 20:49:43 CEST Vladislav Kalko wrote:
> Hello!
> I noticed following issue while using XStream library bundled in Quarkus
> (tested using default version 1.4.14 and latest 1.4.17 added manually):
>
> during deserialization of Externalizable object (of avro-generated class),
> which has field of type Long and value greated than 1073741823L following
> exception appears:
>
> com.thoughtworks.xstream.converters.ConversionException:
> ---- Debugging information ----
> cause-exception : java.lang.ClassCastException
> cause-message : class [B cannot be cast to class java.lang.Byte ([B
> and java.lang.Byte are in module java.base of loader 'bootstrap')
> class : org.acme.Entity
> required-type : org.acme.Entity
> converter-type :
> com.thoughtworks.xstream.converters.reflection.ExternalizableConverter
> path : /org.acme.Entity
> line number : 4
> version : 1.4.17
> -------------------------------
> If value of the field is 1073741823L and less, there is no error.
>
> Project to reproduce: https://github.com/vkalko/XStreamAvroIssue
> Just run MainTest in test/java/org/acme
> <https://github.com/vkalko/XStreamAvroIssue/tree/master/src/test/java/org/ac
> me> .

Sorry, I am mot involved in Quarkus and the code you've provided does not use
XStream in any visible way. I have no idea what Quarkus does with XStream and
how it sets up its configuration.

However, I can assure you, that XStream will deserialize "<long>1073741824</
long>" without any problem into the appropriate Long value.

> I will really appreciate any help and will glad to answer your questions
> and provide additional information if necessary.

The error message implies that XStream is deserializing a byte array and no
long value at all. You will have to look at Quarkus. If I had to guess, I
would look at the BinaryMessageEncoder/BinaryMessageDecoder which seems to be
indirectly used by the calls to for readExternal/writeExternal.

Regards,
Jörg


Vladislav Kalko

unread,
May 19, 2021, 6:18:05 AM5/19/21
to XStream User
Thank you for your answer.
I tried to serialize and deserialize simple Avro entity (Externalizable object) with just XStream. The error also appears in this case.
Interesting thing:  ExternalizableConverter serializes these two entities:

Entity entity1 = new Entity(1L, 1073741823L);
Entity entity2 = new Entity(2L, 1073741824L);

differently:
<org.acme.Entity>
  <byte>2</byte>
  <byte>2</byte>
  <byte>-2</byte>
  <byte>-1</byte>
  <byte>-1</byte>
  <byte>-1</byte>
  <byte>7</byte>
</org.acme.Entity>

and

<org.acme.Entity>
  <byte>4</byte>
  <byte>2</byte>
  <byte-array>gICAgAg=</byte-array>
</org.acme.Entity>

respectively. For values less than Integer.MAX_VALUE / 2 it is ok, but for values greater than Integer.MAX_VALUE / 2,
<byte-array> appears and as a result ClassCastException occur during this cast: (Byte) byte[] as the exception describes.
Here is repo to verify:
https://github.com/vkalko/XStreamAvro/blob/master/src/main/java/org/acme/Main.java

Jörg Schaible

unread,
May 19, 2021, 2:41:19 PM5/19/21
to XStream User
Hi,
OK, this simply verifies my assumption. However, XStream has no control over
the stuff that is written into the ObjectOutputStream and what is read from the
ObjectInputStream at deserialization time.

You will still have to look at the implementaion of the writeExternal and
readExternal methods. It the latter does not understand what the former has
written, it is not XStream's fault. Java serialization will error out exactly
the same.

Regards,
Jörg


Reply all
Reply to author
Forward
0 new messages