简体   繁体   中英

Different serialVersionUID with different Java Versions

i have a weird Problem with the Java serialization/de-serialization.

Besides all other problems with serialization and the proper usage of serialVersionUIDs such a behaviour is completely new to me:

On one machine my software is running on (openSuse 13.1) a update switched the Java version to Java 8. Now, i get a java.io.InvalidClassException if i try to reopen a project file of the software (which is a serialized Java Object) because one of the included classes has the wrong serialVersionUID. The weird thing is, that these class is a class from an external library and has not changed several month (but has no hard coded serialVersionUID field).

If i switch back to Java 7 on that machine, the error do not occur. I can reproduce that error on other machines with openSuse 13.1 + Java 8 but not with machines with Windows or other Linux distributions (like Ubuntu) with Java 8 (or Java 7).

On all machines the official sun/oracle JRE package is installed.

So, has anybody faced that problem at any time? I do not think that it is a bug in Java 8, because it only occurs on an openSuse 13.1 machine. But how could the guys from openSuse mess up their system such, that java would hash the class in a different way as before (as Java has not changed that process in a new version)?

EDIT: To be clear, the class who causes the problem is from an external library. It has not changed in month. And the solution can not be to define a serialVersionUID, because that error has some other sources and would still be there. And i think, it would not stop with this class, it would affect all classes from my used libraries with no defined serialVersionUID

EDIT2: Here is the exact error:

java.io.InvalidClassException: edu.uci.ics.jung.graph.util.Pair; local class incompatible: stream classdesc serialVersionUID = 7664847375082415686, local class serialVersionUID = -638192081897624765 

On all other machines i can test it, the class has the hashed serialVersionUID 7664847375082415686, only openSuse 13.1 + Java 8 get a result of -638192081897624765

has anybody faced that problem at any time?

You have done well to have not found this issue. All the IDEs have a warning for Serializable classes with a serialVersionUID AFAIK. It's a common issue, or rather it is common for people to hardcode the serialVersionUID so they don't see it. Note: eclipse and Oracle JDKs produce different UID for the same version of Java.

because it only occurs on an openSuse 13.1 machine.

This would be very surprising. The same version of Java should produce the same serialVersionUID on every OS.

Note: you can set the serialVersionUID to any thing you need. eg say you need to read an object with a given serialVersionUID, you can set it to the expect UID and it will attempt to read any version you want.

We found out a while back that the source of our problem was because we had an active service running in the background that was compiled with an older version of Java. This service was set to start automatically. Therefore, rebooting the computer didn't work for obvious reasons. This was the result of a defect on our software uninstaller. We often install builds on our machines to test fielded versions of our software. In this particular case, in one machine there was an active service that was conflicting with our software; even though we were running it from Eclipse.

I would suggest to anyone experiencing similar issues to verify that an old service is not creating the conflict. Make sure you uninstall or disable the suspect service and try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM