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

大憨熊 提交于 2019-12-19 03:58:56

问题


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.

来源:https://stackoverflow.com/questions/39945807/how-to-deserialize-object-in-openjdk-android-7-which-has-been-serialized-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!