Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where can I set the stream classdesc serialVersionUID?

I am using a class that implements Serializable from a jar, and to make sure there won't be compiler related issues I gave it a serialVersionUID private static final long serialVersionUID = 123L;

I then recreated the jar but now when I am using the class inside the new jar it is giving me the exception:

java.io.InvalidClassException: com.placeiq.piqhash.PIQDeviceId; local class incompatible: stream classdesc serialVersionUID = 1568630193381428614, local class serialVersionUID = 123

So my question is: 1, What is the stream classdesc serialVersionUID? 2, What can I do to set it so that the two serialVersionUID are the same?

Thanks!

like image 929
Liang Avatar asked Oct 04 '22 01:10

Liang


1 Answers

A serialized version of that class is coming from somewhere (in a stream) and it has a serial version ID of 1568... but it can't be deserialized to your class version (the local class) which is 123.

You need to figure out where that other version is coming from. Then you need to use your new jar, with the new version of the class where ever that is (if you can).

Some possible sources:

  • A network message from some other computer is coming into your program with a serialized instance of that class. (This could be raw socket messages or RMI or anything that uses Java serialization. It is not going to be a JSON message or XML message that gets mapped to that object.)

  • Another program or an older version of your program wrote an instance of the class to a file on disk (or otherwise withing the file system) and your program is not retrieving it.

  • Your program has two versions of the jar--an old one and a new one--that are present, usually because of different classloaders. (This can happen if you aren't careful to manage all the classpaths available on a Java EE container of some sort, including Tomcat or Jetty.)

This is not an exhaustive list.

like image 52
Lee Meador Avatar answered Oct 05 '22 14:10

Lee Meador