Issue 4271: IDL/Java issue, Mapping for IDL enum (java-rtf) Source: (, ) Nature: Uncategorized Issue Severity: Summary: an earlier issue (#1752) described the problem that the singleton assumption for Java enum objects does not hold if these Java objects are serialized, i.e. stored in a file. The issue was closed without any comments, it seems (http://cgi.omg.org/issues/issue1752.txt.) However, the problem remains and is aggravated by the fact that in the more recent documents mappend Java enum classes are required to transitively implement java.io.Serializable! This means that the "singleton assumption" is broken as soon as an enum object is read in from a file, and equality tests fail, e.g. in generated code of unions that have enum switch types! I would thus ask for the same thing as Bruce Schuchardt did back then (quoted from the original mail for issue #1752): > Please consider revising the mapping of enums to require generation > of equality and hash methods that are class and value based. > Application developers should then be advised to use equals() > when comparing enum objects. This is the only way to reconcile enums with Java serialization! Regards, Gerald Brose. Resolution: Incorporate the revised text and close issue Revised Text: In section 1.7, first paragraph: replace with An IDL enum is mapped to a Java class which implements IDLEntity with the same name as the enum type which declares a value method, two static data members per label, an integer conversion method, a protected constructor, and a readResolve method as follows: In section 1.7, add to the end of public class : Object readResolve() throws java.io.ObjectStreamException { ... } In section 1.7, add to the end of the paragraph that begins "There shall be only one instance of an enum.": Note that it is necessary to supply a readResolve method to enforce uniqueness of enum elements, as otherwise serialization followed by deserialization will create a new element. In section 1.7.1, add to the end of public class EnumType: Object readResolve() throws java.io.ObjectStreamException { return from_int( value() ) ; } Actions taken: April 14, 2001: received issue May 13, 2002: closed issue Discussion: issue related to issue 1752 (which has been closed) End of Annotations:===== Date: Sat, 14 Apr 2001 16:46:46 +0200 From: Gerald Brose Organization: Freie Universitt Berlin X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: issues@omg.org CC: java-rtf@omg.org, Gerald Brose Subject: IDL/Java issue, Mapping for IDL enum, renew issue #1752! Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii X-UIDL: emn!!A`M!!ZbL!!YX`d9 Hello, an earlier issue (#1752) described the problem that the singleton assumption for Java enum objects does not hold if these Java objects are serialized, i.e. stored in a file. The issue was closed without any comments, it seems (http://cgi.omg.org/issues/issue1752.txt.) However, the problem remains and is aggravated by the fact that in the more recent documents mappend Java enum classes are required to transitively implement java.io.Serializable! This means that the "singleton assumption" is broken as soon as an enum object is read in from a file, and equality tests fail, e.g. in generated code of unions that have enum switch types! I would thus ask for the same thing as Bruce Schuchardt did back then (quoted from the original mail for issue #1752): > Please consider revising the mapping of enums to require generation > of equality and hash methods that are class and value based. > Application developers should then be advised to use equals() > when comparing enum objects. This is the only way to reconcile enums with Java serialization! Regards, Gerald Brose. -- Gerald Brose, Mail: brose@inf.fu-berlin.de FU Berlin (for PGP key see:) http://www.inf.fu-berlin.de/~brose Institut f. Informatik Ph-one: (++49-30) 838-75112 Berlin, Germany Ph-ax: (++49-30) 838-75109 Date: Sun, 15 Apr 2001 18:33:09 -0400 From: Bob Scheifler User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; m18) Gecko/20010131 Netscape6/6.01 X-Accept-Language: en MIME-Version: 1.0 To: Gerald Brose CC: java-rtf@omg.org Subject: Re: IDL/Java issue, Mapping for IDL enum, renew issue #1752! References: <3AD862D6.35B593@inf.fu-berlin.de> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii; format=flowed X-UIDL: Kl`d9,8fd9[kk!!T=p!! Please consider revising the mapping of enums to require generation of equality and hash methods that are class and value based. Application developers should then be advised to use equals() when comparing enum objects. This is the only way to reconcile enums with Java serialization! On the contrary, the standard implementation technique in such cases is to use a readResolve method that returns canonical instances. - Bob Date: Mon, 16 Apr 2001 10:08:50 +0200 From: Gerald Brose Organization: Freie Universitt Berlin X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: Bob Scheifler CC: java-rtf@omg.org, Gerald Brose Subject: Re: IDL/Java issue, Mapping for IDL enum, renew issue #1752! References: <3AD862D6.35B593@inf.fu-berlin.de> <3ADA21A5.2050203@east.sun.com> Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii X-UIDL: `p;e9b!]d9MJmd9VG>!! Bob Scheifler wrote: > > > >> Please consider revising the mapping of enums to require generation > >> of equality and hash methods that are class and value based. > >> Application developers should then be advised to use equals() > >> when comparing enum objects. > > > > > > This is the only way to reconcile enums with Java serialization! > > On the contrary, the standard implementation technique in such cases > is to use a readResolve method that returns canonical instances. Yes, you are right, of course. I had forgotten about readResolve() (which is a lot better and requires no changes to application code like using equals() instead of ==). It still requires modification of the language mapping, though. I would thus ask to revise the mapping to add a readResolve() method to every mapped Java enum class like this: Object readResolve() throws java.io.ObjectStreamException { return from_int( value() ); } Regards, Gerald Brose P.S.: I just modified the JacORB IDL compiler this way, and it does the trick. -- Gerald Brose, Mail: brose@inf.fu-berlin.de FU Berlin (for PGP key see:) http://www.inf.fu-berlin.de/~brose Institut f. Informatik Ph-one: (++49-30) 838-75112 Berlin, Germany Ph-ax: (++49-30) 838-75109 Date: Tue, 11 Dec 2001 23:06:04 -0800 (PST) From: Ken Cavanaugh Reply-To: Ken Cavanaugh Subject: Proposal for issue 4271 To: java-rtf@omg.org MIME-Version: 1.0 Content-MD5: LBsLDRjItS7ZGmK/s77C4g== X-Mailer: dtmail 1.3.0 @(#)CDE Version 1.3.5 SunOS 5.7 sun4u sparc Content-Type: TEXT/plain; charset=us-ascii X-UIDL: )X^d9%\Ke9OM^d9ImT!! Issue 4271: Java mapping of Enum should have readResolve method As was discussed in the issue, we need to add a readResolve method to the code generated for an Enum so that serialization and deserialization preserves the identity of Enum elements. This just requires adding Object readResolve() throws java.io.ObjectStreamException { return from_int( value() ) ; } to the Enum class. Revised text: In section 1.7, first paragraph: change to An IDL enum is mapped to a Java class which implements IDLEntity with the same name as the enum type which declares a value method, two static data members per label, an integer conversion method, a protected constructor, and a readResolve method as follows: In section 1.7, add to the end of public class : Object readResolve() throws java.io.ObjectStreamException { ... } In section 1.7, add to the end of the paragraph that begins "There shall be only one instance of an enum.": Note that it is necessary to supply a readResolve method to enforce uniqueness of enum elements, as otherwise serialization followed by deserialization will create a new element. In section 1.7.1, add to the end of public class EnumType: Object readResolve() throws java.io.ObjectStreamException { return from_int( value() ) ; }