users@glassfish.java.net

Re: Can't deserialize enum

From: Joe Jordan <joe.glassfish_at_psychlaw.com.au>
Date: Tue, 22 Jul 2008 02:31:12 +1000

Hi Chris,

Thanks for the reply. Unfortunately, 1.5.0_13 shares the same
crashing problem that 1.5.0_09 has.

I have since found that with Glassfish 9.1ur1 and JDK 1.5.0_16 it is
possible to serialize most enums over RMI/IIOP.

public enum ThisWorks {
    foo;
    public String toString() { return "works"; }
}

public enum ThisDoesNot {
    foo {
        public String toString() { return "broken"; }
    }
}

If I can reproduce this on 9.1ur2 I will raise a bug tomorrow (unless
there's a good reason not to?)

Cheers,
Joe


On 22/07/2008, at 2:13 AM, Chris Donaldson wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>