bug 2602 ClassCastException

The cause is simple though the solution is not. Basically the SavedGameUpdater creates a special “Replace” Decorator which will use its normal mechanism to replace the ‘old’ piece by its ‘new’ incarnation. To make this work it must fool the new Decorator that the original old piece was its outermost Decorator (since this is the object which everything outside points to the piece by). It does this by making ‘outer’ point to the original GamePiece (lets ignore why it does this by setProperty() rather than setOuter() ) Now if GamePiece is a Decorator this is fine but if the Piece has no Decorators its a BasicPiece and the cast cannot happen when it is assigned to ‘Decorator dec’.

Anyone working on this bug?

Update VASSAL.tools.SavedGameUpdater

Very Quick Fix: add ‘if (p instanceof Decorator) do it else report error’ at line 83

Quick Fix: Copy all the relevant code out of the “Replace Decorator” and make a method which does what is required in this class even for a BasicPiece

Better Fix: Do the replacement on a hook out of BasicCommandEncoder.decode(String) in the “add” branch. The saved game update will happen as the game is loaded - so can be available whenever loading a game.

Even Better Fix: Work on matchTraits (copied from VASSAL.counter.Replace) to work when order of Decorators is changed.

Best Fix: More work on matchTraits to handle where the definition of a decorator has changed but the state can be re-used. EG new level added to Embellishment but want to retain the current level.