fix: NPE in handleRecentResourceUpdate for an unknown secondary resource - #3519
Draft
csviri wants to merge 1 commit into
Draft
fix: NPE in handleRecentResourceUpdate for an unknown secondary resource#3519csviri wants to merge 1 commit into
csviri wants to merge 1 commit into
Conversation
`ExternalResourceCachingEventSource.handleRecentResourceUpdate` checks
that the primary has an entry in the cache, but then dereferences the
per-secondary lookup without checking it:
R actualResource = actualValues.get(resourceId);
if (actualResource.equals(previousVersionOfResource)) {
`actualValues.get(resourceId)` returns null whenever the primary has a
cache entry but that particular secondary id is not in it, which throws a
NullPointerException. This is reachable from
`AbstractEventSourceHolderDependentResource.onUpdated` for any
`RecentOperationCacheFiller` event source, e.g. after an update whose
resource id is not the one currently cached for that primary.
Skips the cache update when the resource is not tracked, which matches
the intent of the surrounding "only overwrite if we still hold the
version the caller saw" check.
Adds a regression test that fails with NullPointerException without this
change.
16 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a NullPointerException in ExternalResourceCachingEventSource.handleRecentResourceUpdate when a primary is cached but the specific secondary resource ID is not tracked, aligning behavior with the intended “only overwrite if the cached value matches the caller’s previous version” semantics.
Changes:
- Guarded the equality check in
handleRecentResourceUpdateto avoid dereferencing a missing cached secondary entry. - Added a regression test ensuring updates for unknown secondary resources are ignored (and do not throw).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSource.java | Adds a null check before comparing cached vs previous resource to prevent NPE and skip untracked secondary updates. |
| operator-framework-core/src/test/java/io/javaoperatorsdk/operator/processing/event/source/ExternalResourceCachingEventSourceTest.java | Adds a regression test covering the “unknown secondary ID” update scenario. |
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.
ExternalResourceCachingEventSource.handleRecentResourceUpdatechecksthat the primary has an entry in the cache, but then dereferences the
per-secondary lookup without checking it:
actualValues.get(resourceId)returns null whenever the primary has acache entry but that particular secondary id is not in it, which throws a
NullPointerException. This is reachable from
AbstractEventSourceHolderDependentResource.onUpdatedfor anyRecentOperationCacheFillerevent source, e.g. after an update whoseresource id is not the one currently cached for that primary.
Skips the cache update when the resource is not tracked, which matches
the intent of the surrounding "only overwrite if we still hold the
version the caller saw" check.
Adds a regression test that fails with NullPointerException without this
change.
Part of #3517