From 40c089070be7ffd146078af521648329181a3055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20M=C3=A9sz=C3=A1ros?= Date: Wed, 29 Jul 2026 18:20:37 +0200 Subject: [PATCH] fix: use the null-guarded metrics field in the Controller constructor 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. --- .../java/io/javaoperatorsdk/operator/processing/Controller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java index 5df4a86f57..612c3d36f9 100644 --- a/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java +++ b/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/Controller.java @@ -138,7 +138,7 @@ public Controller( kubernetesClient, configuration.getResourceClass()); initAndRegisterEventSources(eventSourceContext); - configurationService.getMetrics().controllerRegistered(this); + metrics.controllerRegistered(this); } @Override