fix: use the null-guarded metrics field in the Controller constructor - #3531
Draft
csviri wants to merge 1 commit into
Draft
fix: use the null-guarded metrics field in the Controller constructor#3531csviri wants to merge 1 commit into
csviri wants to merge 1 commit into
Conversation
The constructor deliberately guards against a null `Metrics`:
this.metrics = Optional.ofNullable(configurationService.getMetrics()).orElse(Metrics.NOOP);
but its last statement bypasses that guard and calls the getter again:
configurationService.getMetrics().controllerRegistered(this);
so a `ConfigurationService` whose `getMetrics()` returns null fails with a
NullPointerException during controller construction, which is exactly what
the guard three lines up is meant to prevent. `EventProcessor` applies the
same `!= null ? metrics : Metrics.NOOP` guard, so the codebase does treat
a null `Metrics` as reachable even though the interface default returns
`Metrics.NOOP`.
Uses the already-resolved `metrics` field instead.
16 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a controller-construction correctness bug in operator-framework-core where the constructor would bypass the null-guarded metrics field and re-fetch Metrics from ConfigurationService, causing a potential NullPointerException when getMetrics() returns null.
Changes:
- Use the already null-guarded
metricsfield to callcontrollerRegistered(this)instead of callingconfigurationService.getMetrics()again.
| configuration.getResourceClass()); | ||
| initAndRegisterEventSources(eventSourceContext); | ||
| configurationService.getMetrics().controllerRegistered(this); | ||
| metrics.controllerRegistered(this); |
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.
The constructor deliberately guards against a null
Metrics:but its last statement bypasses that guard and calls the getter again:
so a
ConfigurationServicewhosegetMetrics()returns null fails with aNullPointerException during controller construction, which is exactly what
the guard three lines up is meant to prevent.
EventProcessorapplies thesame
!= null ? metrics : Metrics.NOOPguard, so the codebase does treata null
Metricsas reachable even though the interface default returnsMetrics.NOOP.Uses the already-resolved
metricsfield instead.Part of #3517