Skip to content
Permalink
Browse files
Merge branch 'enum_fix' into 'ibm-trunk'
Enum fix

Demarshalling of Java Enums need to be special-cased - the demarshalled value needs to be obtained via a call to
Enum.valueOf(type, name) as Enum values are singletons.

See merge request !25
  • Loading branch information
ngmr committed Apr 10, 2015
2 parents 82a62e3 + 8f6a2d7 commit 5b8f2a3f96e57af1a70d0dae4bcbee57db179da4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
@@ -24,6 +24,7 @@
import java.io.Serializable;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Vector;

@@ -194,6 +195,20 @@ public void testBasicSerializable() throws RemoteException {
SampleSerializable ser2 = (SampleSerializable) sample.getSerializable();
}

public void testEnum() throws RemoteException {
SampleEnum se = SampleEnum.SAMPLE2;
sample.setSerializable(se);
Serializable s = sample.getSerializable();
assertSame(se, s);
}

public void testEnumArray() throws RemoteException {
SampleEnum[] sa = { SampleEnum.SAMPLE3, SampleEnum.SAMPLE1, SampleEnum.SAMPLE3 };
sample.setSerializable(sa);
Object[] oa = (Object[])sample.getSerializable();
assertTrue(Arrays.deepEquals(sa, oa));
}

public void testRemoteAttributeOnServer() throws RemoteException {
SampleSerializable ser = new SampleSerializable();
ser.setRemote(sample);
@@ -334,6 +349,8 @@ public static void main(String[] args) throws Exception {
test.testCorbaAttribute(SampleCorbaHelper.narrow(sampleCorbaRef));
test.testComplexCorbaAttribute(SampleCorbaHelper.narrow(sampleCorbaRef));
test.testHashMap();
test.testEnum();
test.testEnumArray();
//myORB.destroy();
System.out.println("Testing complete");
}
@@ -0,0 +1,5 @@
package test.rmi;

public enum SampleEnum {
SAMPLE1, SAMPLE2, SAMPLE3
}
@@ -22,6 +22,7 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectStreamField;
import java.io.Reader;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -51,6 +52,7 @@ public class ValueDescriptor extends TypeDescriptor {
static final Logger logger = Logger.getLogger(ValueDescriptor.class
.getName());

protected boolean _is_enum;
protected boolean _is_externalizable;

protected boolean _is_serializable;
@@ -125,6 +127,7 @@ public String getRepositoryID() {
}

long getSerialVersionUID() {
if (_is_enum) return 0L;
if (_serial_version_uid_field != null) {

try {
@@ -157,6 +160,7 @@ public void init0() {
final Class type = getJavaClass();
final Class superClass = type.getSuperclass();

_is_enum = Enum.class.isAssignableFrom(type);
_is_rmi_stub = RMIStub.class.isAssignableFrom(type);
_is_externalizable = java.io.Externalizable.class
.isAssignableFrom(type);
@@ -657,6 +661,18 @@ public java.io.Serializable createBlankInstance() {
public java.io.Serializable readValue(
final org.omg.CORBA.portable.InputStream in,
final java.util.Map offsetMap, final java.lang.Integer offset) {
if (_is_enum) {
try {
in.read_long(); // read in and ignore Enum ordinal
final String name = (String)((org.omg.CORBA_2_3.portable.InputStream)in).read_value(String.class);
final Enum value = Enum.valueOf(getJavaClass(), name);
offsetMap.put(offset, value);
return value;
} catch (org.omg.CORBA.portable.IndirectionException ex) {
return (Serializable)offsetMap.get(new Integer(ex.offset));
}
}

final java.io.Serializable value = createBlankInstance();

offsetMap.put(offset, value);

0 comments on commit 5b8f2a3

Please sign in to comment.