Name: rm29839 Date: 05/21/98
import java.io.*;
import java.net.*;
public class SerialServer {
static public void main(String args[]) throws Exception {
ServerSocket server = new ServerSocket(12345);
System.out.println("server listening on port "+server.getLocalPort());
Socket client = server.accept();
ObjectInputStream ois =
new ObjectInputStream(client.getInputStream());
for(;;) {
System.out.println(ois.readObject());
}
}
}
import java.io.*;
import java.net.*;
import java.util.*;
public class SerialClient {
static public void main(String args[]) throws Exception {
Socket server = new Socket("localhost", 12345);
System.out.println("connected to port " + server.getLocalPort());
ObjectOutputStream oos =
new ObjectOutputStream(server.getOutputStream());
oos.writeObject(System.getProperties());
oos.flush();
oos.close();
}
}
run the server:
$ java -version
java version "1.2beta3"
$ java SerialServer
server listening on port 12345
run the client:
$ java -version
java version "1.1.5"
$ java SerialClient
connected to port 44953
the server will crash with:
java.io.InvalidClassException: java.util.Properties; Local class not compatible: stream classdesc serialVersionUID=4112578634029874840 local class serialVersionUID=-6012469190225919654
at java.io.ObjectStreamClass.setClass(ObjectStreamClass.java:378)
at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java:776)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:358)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:233)
at java.io.ObjectInputStream.inputObject(ObjectInputStream.java:963)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:374)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:233)
at SerialServer.main(SerialServer.java:12)
1.1.5 also fails to deserialize properties serialized with 1.2b3.
jm.
(Review ID: 28846)
======================================================================
- duplicates
-
JDK-4126047 The serializable class java.util.Properties evolved incompatibly.
-
- Closed
-