users@glassfish.java.net

Re: Can't deserialize enum

From: Chris Donaldson <Christopher.Donaldson_at_Sun.COM>
Date: Mon, 21 Jul 2008 11:13:25 -0500

Hi Joe,

Java 1.5.0_14 resolved CR # 6296049. Based on various specs, enum
constants should not be subject to default RMI-JRMP serialization and
allowing this was a bug.

http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.9

"It is a compile-time error to attempt to explicitly instantiate an enum
type (§15.9.1). The final clone method in Enum ensures that enum
constants can never be cloned, and the special treatment by the
serialization mechanism ensures that duplicate instances are never
created as a result of deserialization. Reflective instantiation of enum
types is prohibited. Together, these four things ensure that no
instances of an enum type exist beyond those defined by the enum constants."

As an interim you could test on 1.5.0_13, but going beyond that will
require some code changes.

Regards,
Chris

Joe Jordan wrote:
> Heya folks,
>
> We are trying to upgrade from JDK 1.5.0_09 to 1.5.0_16 due to JVM
> crashes, but it appears enum serialization was totally broken in JDK
> 1.5.0_14.
>
> The errors we are getting are:
>
> Caused by: java.io.InvalidObjectException: can't deserialize enum
> at java.lang.Enum.readObject(Enum.java:205)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
> com.sun.corba.ee.impl.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1679)
>
>
> We get these errors both on Glassfish 9.0_01 and 9.1_01. We also get
> the same problem with JDK 1.6.0_07.
>
> We are familiar with
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=193 and have been
> working around this problem (enums don't preserve reference equality
> over RMI/IIOP) for years now. The comments seem to suggest the issue is
> resolved in "GFv2 b40", but I am fairly sure the version we are on
> (9.1ur1bSomething) is later than this?
>
> Issue #193 also provides a link to a non-existent Glassfish issue at
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=10336 (looks like
> the link should be to OMG, wherever that is).
>
> Does anyone know a workaround/solution to this issue that does not
> involve adding custom writeReplace() serialization logic to all of our
> enums?
>
> Cheers,
> Joe
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>