fix: checking for null to avoid NPE with SSA matching#3037
fix: checking for null to avoid NPE with SSA matching#3037csviri merged 1 commit intooperator-framework:mainfrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a NullPointerException in the SSA (Server-Side Apply) based Kubernetes resource matcher when processing managed fields that reference collections that are null or missing in the actual resource. The fix adds null checks before dereferencing list values in two key methods.
Key changes:
- Added null check in
handleListKeyEntrySetto prevent NPE whenactualValueListis null - Added null check in
handleSetValuesto prevent NPE whenvaluesis null - Added test case with a StatefulSet containing managed fields that reference missing values
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| SSABasedGenericKubernetesResourceMatcher.java | Added null checks in handleListKeyEntrySet and handleSetValues methods to prevent NPE when referenced collections are missing |
| SSABasedGenericKubernetesResourceMatcherTest.java | Added test case statefulSetWithMissingManagedField to verify matching works when managed fields reference missing values |
| statefulset-with-managed-fields-missing.yaml | Added test resource file containing a StatefulSet with managed fields that reference potentially missing values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| if (values == null) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
After adding the null check for values at line 404-406, accessing values.get(0) at line 408 can still throw an IndexOutOfBoundsException if the list is empty. Consider adding a check for values.isEmpty() before accessing the first element.
| } | |
| } | |
| if (values.isEmpty()) { | |
| continue; | |
| } |
closes: operator-framework#3034 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
closes: #3034