Guard against null metadata node in ShadowStateMetadata.buildMetadata (fixes NPE) - #223
Open
Atsushi570 wants to merge 2 commits into
Open
Guard against null metadata node in ShadowStateMetadata.buildMetadata (fixes NPE)#223Atsushi570 wants to merge 2 commits into
Atsushi570 wants to merge 2 commits into
Conversation
…adata buildMetadata dereferenced the metadata node without a null check when the delta node was an array or object. When the delta and the desired metadata are structurally inconsistent (a delta node exists at a path where the desired metadata is null/missing), this threw a NullPointerException, aborting the shadow update and preventing the delta from being published. In steady state this repeats on every subsequent update to the affected shadow. Add an isNullOrMissing(metadataNode) guard so the subtree is skipped gracefully, plus a regression test. See aws-greengrass#222 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
saranyailla
approved these changes
Aug 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue
Fixes the
NullPointerExceptionreported in #222.Problem
ShadowStateMetadata.getDeltaMetadata(delta)callsbuildMetadata(delta, desired).buildMetadatarecurses the delta tree and dereferences the corresponding metadata node without a null guard:When a delta node exists at a path where the
desiredmetadata subtree isnull/missing (a state vs. metadata structural inconsistency),metadataNodeisnulland the array/object handling throws NPE.Observed on a production Greengrass device (Nucleus 2.16.1 / ShadowManager 2.3.12): a local pub/sub shadow
updatefails with:The exception is unhandled at the IPC layer, so the update is dropped (
PubSubIntegrator: Unable to perform shadow operation), the delta is never published, and every subsequent update to the affected shadow repeats the NPE.Fix
Add an
isNullOrMissing(metadataNode)guard inbuildMetadataright after the value-node check. If there is no metadata for a delta subtree, the subtree is skipped (returnsnull) instead of dereferencing null in the array/object handling. This also naturally covers the array-index case where the metadata array is shorter than the delta array (ArrayNode.get(i)returnsnullfor an out-of-range index, which now recurses into the guarded branch).Test
Added
GIVEN_delta_field_missing_from_metadata_WHEN_getDeltaMetadata_THEN_does_not_throw: a delta with an array field whose desired metadata has no corresponding node. Before the fix this threw NPE; after the fixgetDeltaMetadatacompletes, keeps fields that do have metadata, and treats the field with missing metadata as null/missing.Notes