Benjamin Schieder


2014 June 13 | 0 comments

I just released Space Trader version 1.1.0. The ChangeLog:

  • Tag version: 1.1.0
  • Fix: in SellCargo dialog, show correct values for profit/loss margin and buying price
  • Fix: In Search dialog, make textView fill the whole width
  • Fix: In WarpSystemInfo dialog, right-align target system name
  • Change: Change format of savegame. This breaks savegame compatibility now but preserves it in the long run.

So, yeah, the interesting part is obviously the last line. Why would I break savegame compatibility on the SECOND release? Well, it’s because I didn’t understand how works, that’s why.

My assumption about was that it somehow extracted all the fields from the object and dumped it into an output stream. Turns out, it also writes an additional variable serialVersionUID to the file to check if it’s later reading a compatible version of the object to cast back to its original class. That’s all fine, but unfortunately this UID also changes when a method of the class changes. So, add another constructor, you can’t load your savegame anymore.

So, why should this matter? SaveGame is its own class after all. Yes, but it has fields of types “Ship”, “CrewMember” and “SolarSystem”. These might change between releases, in turn changes the serialVersionUID of THOSE classes and ‘‘BOOM’’ you can’t read the savegame anymore.
This is STILL not what my problem was here. The Ship class has a field referencing a GameState. And THAT changed from 1.0 to 1.1.0 to fix the haggling computer you get after the Jarek quest.

So now I made a new class SaveGame_v110 that uses only primitive types (int, boolean, String) and added a contructor to GameState for that class. This DOES break savegame compatibility as described, but now I can change GameState and any other classes as I want to, but SaveGame_v110 will not be affected and still loading. Let’s hope it stays that way.


Category: blog

Tags: Android SpaceTrader Java Serializable

Post a comment

All comments are held for moderation; basic HTML formatting is accepted.

Name: (required)
E-mail: (required, not published)
Website: (optional)