-
Enhancement
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta2
-
x86
-
windows_nt
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2033232 | 1.4.0 | Everett Anderson | P4 | Closed | Fixed | merlin |
Name: skT45625 Date: 04/05/2000
java version "1.3.0rc1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc1-T)
Java HotSpot(TM) Client VM (build 1.3.0rc1-S, mixed mode)
In RMI-IIOP, when passing an object by value that has a field assigned to this,
the field is still null within readObject() after defaultReadObject() is called,
although it is correctly assigned to this after deserialization is complete.
This behaviour is different to RMI-JRMP (and file serialization), where the
field is assigned to this by defaultReadObject().
This causes a problem if some extra initialisation code is placed within
readObject(), for example to initialise transient fields, that is dependent on
the deserialized data.
Here is a program that demonstrates the problem (code in file Test.java):
class Value implements java.io.Serializable
{
public Value partner;
public Value()
{
partner = this;
}
private void readObject( java.io.ObjectInputStream theIS )
throws java.io.IOException, ClassNotFoundException
{
theIS.defaultReadObject();
System.out.println( "Read value: " + partner );
}
private void writeObject( java.io.ObjectOutputStream theOS )
throws java.io.IOException
{
theOS.defaultWriteObject();
System.out.println( "Write value: " + partner );
}
public String toString() { return "value"; }
}
interface TestInt extends java.rmi.Remote
{
Value getValue( Value val ) throws java.rmi.RemoteException;
}
public class Test implements TestInt
{
public Test() throws java.rmi.RemoteException
{
java.rmi.server.UnicastRemoteObject.exportObject( this );
javax.rmi.PortableRemoteObject.exportObject( this );
}
public Value getValue( Value val ) { return val; }
public static void main( String[] args )
{
System.setProperty( "java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory" );
try
{
java.rmi.Naming.rebind( "Test-JRMP", new Test() );
new javax.naming.InitialContext().rebind( "Test-IIOP",
new Test() );
}
catch ( Exception e )
{
e.printStackTrace();
}
try
{
TestInt jrmpTest = (TestInt) java.rmi.Naming.lookup(
"Test-JRMP" );
TestInt iiopTest = (TestInt)
javax.rmi.PortableRemoteObject.narrow(
new javax.naming.InitialContext().lookup(
"Test-IIOP" ), TestInt.class );
System.out.println( "Testing JRMP" );
Value jrmpVal = jrmpTest.getValue( new Value() );
System.out.println( "After read: " + jrmpVal.partner );
System.out.println();
System.out.println( "Testing IIOP" );
Value iiopVal = iiopTest.getValue( new Value() );
System.out.println( "After read: " + iiopVal.partner );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}
Compile with commands:
javac Test.java
rmic Test
rmic -iiop Test
Run rmiregistry and tnameserv in background.
Run command:
java Test
Output is:
Testing JRMP
Write value: value
Read value: value
Write value: value
Read value: value
After read: value
Testing IIOP
Write value: value
Read value: null
Write value: value
Read value: null
After read: value
I would expect the "null"s in the IIOP output to be "value"s, as for JRMP.
(Review ID: 102901)
======================================================================
- backported by
-
JDK-2033232 Field set to null instead of this by defaultReadObject() in RMI-IIOP
-
- Closed
-