ConcurrentHashMap ConversionException on Java 8

104 views
Skip to first unread message

Thirunavukkarasu Dhanushkodi

unread,
Nov 9, 2021, 8:50:24 PM11/9/21
to XStream User
Hi Team --

 We have serialized set of object along with concurrent hashmap in xstream 1.3.1 jar with java 7 version. however when we are upgrade the java 8 , it's throwing an below error 

Java 8 and xstream 1.3.1

com.thoughtworks.xstream.converters.reflection.ObjectAccessException: No such field java.util.concurrent.ConcurrentHashMap.segmentMask
com.thoughtworks.xstream.converters.ConversionException: Could not call java.util.concurrent.ConcurrentHashMap.readObject() : No such field java.util.concurrent.ConcurrentHashMap.segmentMask
---- Debugging information ----
message             : Could not call java.util.concurrent.ConcurrentHashMap.readObject()
cause-exception     : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message       : No such field java.util.concurrent.ConcurrentHashMap.segmentMask
class               : java.util.concurrent.ConcurrentHashMap
required-type       : java.util.concurrent.ConcurrentHashMap
path                : /java.util.concurrent.ConcurrentHashMap/java.util.concurrent.ConcurrentHashMap/default/segmentMask
line number         : 5
-------------------------------

Post have i have upgraded the xstream jar to 1.4.8 since you guys fixed on this version.

Eventually again getting below error when i'm trying to convert back to object from xml

com.thoughtworks.xstream.converters.ConversionException: null : null
---- Debugging information ----
cause-exception     : java.lang.RuntimeException
cause-message       : null
class               : java.util.concurrent.ConcurrentHashMap
required-type       : java.util.concurrent.ConcurrentHashMap
converter-type      : com.thoughtworks.xstream.converters.collections.MapConverter
path                : /java.util.concurrent.ConcurrentHashMap/unserializable-parents
line number         : 2
version             : 1.4.8
-------------------------------

Any thoughts on this ?

Regards,
Thiru


Jörg Schaible

unread,
Nov 10, 2021, 7:52:47 PM11/10/21
to XStream User
Hi,

XStream 1.3.1 has no idea about a ConcurrentHashMap, therefore it will use a
SerializableConverter that is reflection based. However, the Java runtime
changed the implementation details for this type, therefore the XML marshalled
in Java 7 is incompatible when unmarshalled with Java 8. More changes might
have been made in newer Java versions.

XStream added support for the ConcurrentHashMap with XStream 1.4.3. Since this
version, the type is handled by the MapConverter, which does not depend on the
implementation details of the ConcurrentHashMap. However, it will not
unmarshal XML written by the SerializationConverter.

You realize, that we talk about stuff here, that changed a decade ago?

Derive an own converter from the MapConverter that handles the
ConcurrentHashMap. If the first child is not "unserializable-parents", just
call the super methods. If it is, you will need a compatibility mode in this
converter, that locates the elements of the map on its own and calls the
appropriate internal methods of the MapConverter.

BTW: Why do you try to use 1.4.8 and not 1.4.18?

Regards,
Jörg


Am Mittwoch, 10. November 2021, 02:50:23 CET schrieb Thirunavukkarasu
Dhanushkodi:
> Hi Team --
>
> We have serialized set of object along with concurrent hashmap in xstream
> 1.3.1 jar with java 7 version. however when we are upgrade the java 8 ,
> it's throwing an below error
>
> *Java 8 and xstream 1.3.1*
>
> com.thoughtworks.xstream.converters.reflection.ObjectAccessException: No
> such field java.util.concurrent.ConcurrentHashMap.segmentMask
> com.thoughtworks.xstream.converters.ConversionException: Could not call
> java.util.concurrent.ConcurrentHashMap.readObject() : No such field
> java.util.concurrent.ConcurrentHashMap.segmentMask
> ---- Debugging information ----
> message : Could not call
> java.util.concurrent.ConcurrentHashMap.readObject()
> cause-exception :
> com.thoughtworks.xstream.converters.reflection.ObjectAccessException
> cause-message : No such field
> java.util.concurrent.ConcurrentHashMap.segmentMask
> class : java.util.concurrent.ConcurrentHashMap
> required-type : java.util.concurrent.ConcurrentHashMap
> path :
> /java.util.concurrent.ConcurrentHashMap/java.util.concurrent.ConcurrentHashM
> ap/default/segmentMask line number : 5
Reply all
Reply to author
Forward
0 new messages