Remote EJB Marshalling failing with ClassCastException: Cannot cast java.util.TreeMap to ... , when using Collections.emptySortedMap() in JBoss EAP 7

Solution Verified - Updated -

Issue

  • Remote EJB Marshalling failing with ClassCastException: Cannot cast java.util.TreeMap to ... , when using Collections.emptySortedMap() in JBoss EAP 7

The class being serialized is :

import java.io.Serializable;
import java.util.Collections;
import java.util.Date;
import java.util.SortedMap;
import java.util.TreeMap;

public class Example implements Serializable {
  private static final long serialVersionUID = 3L;  
  private SortedMap<String, String> map = Collections.emptySortedMap();
  private Date mop;
}

The exception is:

     [java] java.lang.ClassCastException: Cannot cast java.util.TreeMap to java.util.Date
     [java]     at java.lang.Class.cast(Class.java:3369)
     [java]     at org.jboss.marshalling.reflect.SerializableField.setObject(SerializableField.java:342)
     [java]     at org.jboss.marshalling.river.RiverUnmarshaller.readFields(RiverUnmarshaller.java:1864)
     [java]     at org.jboss.marshalling.river.RiverUnmarshaller.doInitSerializable(RiverUnmarshaller.java:1778)
     [java]     at org.jboss.marshalling.river.RiverUnmarshaller.doReadNewObject(RiverUnmarshaller.java:1406)
     [java]     at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:283)
     [java]     at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:216)
     [java]     at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:41)
     [java]     at WriteReadExample.read(WriteReadExample.java:83)
     [java]     at WriteReadExample.test(WriteReadExample.java:29)
     [java]     at WriteReadExample.main(WriteReadExample.java:20)
     [java] Caused by: an exception which occurred:
     [java]     in field Example.mop
     [java]     in object Example@458c1321
     [java]     in object of type Example

Environment

Red Hat JBoss Enterprise Application Platform (EAP) 7.3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content