Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7949 +/- ##
============================================
+ Coverage 29.77% 29.84% +0.06%
- Complexity 16655 16831 +176
============================================
Files 3134 3140 +6
Lines 301874 302533 +659
Branches 52863 52988 +125
============================================
+ Hits 89895 90300 +405
- Misses 202646 202810 +164
- Partials 9333 9423 +90 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This pull request fixes a critical bug where save game files (including autosaves) could not be loaded due to XStream 1.4's inability to deserialize Java Records. The issue was introduced when BoardLocation was refactored from a class to a Record without adding the necessary XStream converter.
Changes:
- Added a custom XStream converter for BoardLocation Records in SerializationHelper.java to enable proper deserialization
- Used context.convertAnother() to ensure Coords objects are properly registered in XStream's reference tracking system
- Accidentally added an unused import to WeaponHandler.java
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| megamek/src/megamek/common/weapons/handlers/WeaponHandler.java | Adds an unused AbstractReflectionConverter import |
| megamek/src/megamek/common/util/SerializationHelper.java | Implements a custom converter for BoardLocation Records to fix save game deserialization |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…mpt to omit missing subType field
…exts would break XStream reference lookups)
e9e1177 to
03cb567
Compare
This fixes an issue where some save game files - including autosaves - could not be loaded at all due to XStream stupidity regarding Records.
Huge props to @BTSS88 for tracking down the root cause: auto-hit artillery markers (or to be more precise, the BoardLocation data storing those markers' locations, which used to be a class but got refactored to a Record)
XStream 1.4, the version we currently depend on, does not natively support deserializing Records.
This is deeply stupid, but made even more offensive by the fact that it can serialize them just fine.
So every time we add a Record data type that is Serializable, we have to also add a new Converter in
SerializationHelper.javato ensure that this data type can be loaded after saving it.This was not done when BoardLocation was converted to a Record, but it turns out XStream doesn't care if there are no actual BoardLocation entries populated in the save game file so few players noticed.
This patch adds the missing Converter, as well as making sure to call
context.convertAnother()so that any Coords created as part of the BoardLocation load are also registered with proper ID references so that later things like the special hex HashTable don't explode.Testing:
Fix MegaMek/mekhq#8679