Ilya Shinkarenko
Ilya Shinkarenko

Reputation: 2182

How to deserialize object in OpenJDK (Android 7+), which has been serialized in Apache Harmony (Android *-6)?

My app uses http://prevayler.org/ for persistence, piggybacking Java Object serialization. After upgrade to Android 7.0 (Nougat) users cannot open their data, since the deserialization does not work any more:

java.io.StreamCorruptedException: invalid type code: 71
  at java.io.ObjectInputStream.readString(ObjectInputStream.java:1647)
  at java.io.ObjectInputStream.readEnum(ObjectInputStream.java:1737)
  ...
  at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
  at org.prevayler.foundation.serialization.JavaSerializer.readObject(JavaSerializer.java:34)
  ...
  at org.prevayler.PrevaylerFactory.snapshotManager(PrevaylerFactory.java:368)
  at org.prevayler.PrevaylerFactory.create(PrevaylerFactory.java:316)
  at com.tennismath.prevayler.PrevaylerServiceImpl.getSystemPrevayler(PrevaylerServiceImpl.java:51)

While deserializing an enum, the OpenJDK routine reads the unexpected byte value of "71" and throws the exception, as it can be seen from the source code: http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/java/io/ObjectInputStream.java#ObjectInputStream.readString%28boolean%29

I have the following ideas:

  1. Set up a migration server, which would run both Harmony and OpenJDK processes, which would perform data migration.
  2. Hack the binary format and fix the enums serialization (assumed the it is the only one issue, which I doubt)
  3. Hack the deserialization with AspectJ

All these choices seem to be either an overkill or unsatisfying. Before I start hacking the binaries, maybe anybody has a better idea of what can be done to deserialize the old data with the new runtime? Thank you.

Upvotes: 3

Views: 261

Answers (0)

Related Questions