views:

713

answers:

3

Recieved the following exception when deserializing a HashMap<String, Integer>:

java.io.InvalidClassException: java.lang.Integer; local class incompatible: stream classdesc serialVersionUID = 1360826667802527544, local class serialVersionUID = 1360826667806852920

Serialized and deserialized on the same machine, with the same JRE. JDK 1.6.0_12

+1  A: 

Hello, check the source code for Integer, here is what I have for Integer in several verions of java:

/** use serialVersionUID from JDK 1.0.2 for interoperability */
private static final long serialVersionUID = 1360826667806852920L;

So I'd say the problem comes from a class of yours that you changed between serialization and deserialization and that has no specific serialVersionUID...

Maybe you should look at this, same problem description and it looks like wrong serialization / deserialization code....

pgras
It's weird, because the first bunch of digits in the serialized Integer are the same (136082666780...) - which suggests something weird has happened to the serialized file, or perhaps the input stream(?)
harto
OpenJDK 7 (http://hg.openjdk.java.net/icedtea/jdk7/jdk/file/65dfd94650d3/src/share/classes/java/lang/Integer.java) still uses this ID, which is also the ID identified as the "local class". So somehow it looks like you're deserializing a non-standard/incompatible Integer.
Matthew Flaschen
your're right no answer at the momment but if you google 'serialVersionUID = 1360826667802527544' you'll see he is not alone :)
pgras
harto has a point. It could just be good old fashioned file corruption.
Matthew Flaschen
+1  A: 

That shouldn't happen. Note that the IDs differ only in the last few digits; the second one ist the one I see in my JDK sources.

My guess is that the serialized stream got corrupted somehow.

Michael Borgwardt
+4  A: 

From looking at the JDK source, 1360826667806852920 is the correct serialVersionUID for Integer. I wasn't able to find any classes in the JDK with the serialVersionUID 1360826667802527544.

Interestingly, searching for 1360826667802527544 on Google turned up a few other people with this problem, notably this thread on Sun's forums. The problem there was that the person was storing bytes in a String, and the serialized data was getting mangled. Since you're getting the same serialVersionUID it seems very likely that you're running into a similar problem.

Never store bytes in a String. Use a byte array or a class designed to hold bytes, not chars.

Laurence Gonsalves