Fix NPE on partially initialized square grids #4964
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Identify the Bug or Feature request
Fixes #3315
Description of the Change
When our objects are deserialized by XStream, the constructors are not run. In the case of
Grid
implementations, the constructors are relied on to set static state such asSquareGrid.FACING_ANGLES
. Without the constructor running, the state remainsnull
. The bug is not likely reproducible in recent versions since we recreate anyGrid
instances as part of our protobuf logic. But if there is any change there, the bug would resurface.This PR address this by:
Grid
with new methods so callers don't have to care about the facing arrays.Grid
method to calculate results instead.The end result is:
Grid
s to keep the facing arrays up to dateTest cases were added for the new
nearestFacing()
andnextFacing()
methods.Possible Drawbacks
The new
snapFacingInternal()
is not as easy to read as a facing array.Documentation Notes
N/A
Release Notes
This change is