Results 1 to 1 of 1
- 06-08-2010, 09:20 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 1
- Rep Power
- 0
Serialization - ClassCastException: SimpleTimeZone to ZoneInfo in readObject
Hello
I have a java application running on weblogic.
Java version - 1.6.0_17-b04
And a client application written in Java as well (same version).
There are objects with GregorianCalendar which are transfered from server to client via RMI.
I occasionally get the following error:
Caused by: java.lang.ClassCastException: java.util.SimpleTimeZone cannot be cast to sun.util.calendar.ZoneInfo
at java.util.Calendar$1.run(Unknown Source)
at java.util.Calendar$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.util.Calendar.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor23.invoke(Unkno wn Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknow n Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknow n Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknow n Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknow n Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknow n Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unkno wn Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at java.util.ArrayList.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor28.invoke(Unkno wn Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
at java.lang.reflect.Method.invoke(Unknown Source)
I see that the readObject of Calendar code is:
There is casting to ZoneInfo no matter what's the class is actually instance of.Java Code:ZoneInfo zi = null; try { zi = AccessController.doPrivileged( new PrivilegedExceptionAction<ZoneInfo>() { public ZoneInfo run() throws Exception { return (ZoneInfo) input.readObject(); } }, CalendarAccessControlContext.INSTANCE); } catch (PrivilegedActionException pae) { Exception e = pae.getException(); if (!(e instanceof OptionalDataException)) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof ClassNotFoundException) { throw (ClassNotFoundException) e; } throw new RuntimeException(e); } } if (zi != null) { zone = zi; } // If the deserialized object has a SimpleTimeZone, try to // replace it with a ZoneInfo equivalent (as of 1.4) in order // to be compatible with the SimpleTimeZone-based // implementation as much as possible. if (zone instanceof SimpleTimeZone) { String id = zone.getID(); TimeZone tz = TimeZone.getTimeZone(id); if (tz != null && tz.hasSameRules(zone) && tz.getID().equals(id)) { zone = tz; } }
In my case, the calendar sometimes contains SimpleTimeZone and not ZoneInfo which causes for the ClassCastException.
I also find that there are occasions where the zone variable holds SimpleTimeZone (gets to the line "if (zone instanceof SimpleTimeZone)" and equals true) but doesn't fail in "return (ZoneInfo) input.readObject();".
Any idea?
Similar Threads
-
Execution stuck at ObjectInputStream .readObject() with NO Exception thrown.JAVA BUG?
By r00tb33r in forum NetworkingReplies: 2Last Post: 06-01-2010, 02:58 AM -
ClassCastException
By Umi in forum New To JavaReplies: 2Last Post: 01-13-2010, 11:51 PM -
InputStream, Iterator, readObject issues while deserializing multiple objects
By xcallmejudasx in forum New To JavaReplies: 0Last Post: 12-22-2008, 06:16 PM -
ClassCastException
By paulsim in forum Java AppletsReplies: 2Last Post: 08-21-2008, 02:14 PM -
What is Serialization and de-serialization in Java
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks