[kaffe] java.io.ObjectInputStream: final field cannot be restored

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Tue Mar 23 22:02:02 PST 2004


Hi,

Interested in Prevayler (http://www.prevayler.org/), which is
marked untested in our "Compatibility - Application Testing",
I tried it.

The result was unsatisfactory.  The simplest demo of Prevayler
cannot run on kaffe.  After studying the cause of the error,
I found something buggy in java.io.ObjectInputStream.

My test program is attaced below.  The test shows that a
field that is marked "final" cannot be restored by
java.io.ObjectInputStream#readObject.

I tested it on kaffe 1.1.4,  but I have not tested it on the current
CVS version yet.

Results:

The VM on which              The VM
ObjectOutputStream ran       ObjectInputStream ran     Result
----------------------       ---------------------     ------
Kaffe 1.1.4                  Kaffe 1.1.4               FAIL(1)
Sun's 1.4.2_04               Sun's 1.4.2_04            PASS(2)
Kaffe 1.1.4                  Sun's 1.4.2_04            PASS(3)
Sun's 1.4.2_04               Kaffe 1.1.4               FAIL(4)

(1) Kaffe --> Kaffe
$bash java Test01 write | java Test01 read
t2=Test01 at 8291b64 null B
t1=Test01 at 81459b4 A B

(2) Sun --> Sun
bash$ java Test01 write | java Test01 read
t1=Test01 at f9f9d8 A B
t2=Test01 at 1820dda A B

(3) Kaffe --> Sun
bash$ java Test01 write | (Some command that sends data to another machine)
t1=Test01 at 81459b4 A B

bash$ (Some command that received data from another machine) | java Test01 read
t2=Test01 at 1820dda A B

(4) Sun --> Kaffe
bash$ java Test01 write | (Some command that sends data to another machine)
t1=Test01 at f9f9d8 A B

$ (Some command that received data from another machine) | java Test01 read
t2=Test01 at 8291b64 null B

Test program:
import java.io.*;
import java.util.*;
class Test01 implements java.io.Serializable {

  private final String s1 = "A";
  private String s2 = "B";

  public static void main(String args[]) throws Exception {
    if (args[0].equals("write")) {
      Test01 t1 = new Test01();
      ObjectOutputStream stream = new ObjectOutputStream(System.out);
      stream.writeObject(t1);
      stream.flush();
      System.err.println("t1=" + t1 + " " + t1.s1 + " " + t1.s2);
      return;
    }
    if (args[0].equals("read")) {
      ObjectInputStream ois = new ObjectInputStream(System.in);
      Test01 t2 = (Test01)(ois.readObject());
      System.err.println("t2=" + t2 + " " + t2.s1 + " " + t2.s2);
      return;
    }
  }
}




More information about the kaffe mailing list