Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ private static void handleListKeyEntrySet(
result.put(keyInActual, valueList);
var actualValueList = (List<Map<String, Object>>) actualMap.get(keyInActual);

if (actualValueList == null) {
return;
}

var targetValuesByIndex = new TreeMap<Integer, Map<String, Object>>();
var managedEntryByIndex = new HashMap<Integer, Map<String, Object>>();

Expand Down Expand Up @@ -396,6 +400,11 @@ private static void handleSetValues(
continue;
}
var values = (List<?>) actualMap.get(keyInActual);

if (values == null || values.isEmpty()) {
continue;
}
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
}
}
if (values.isEmpty()) {
continue;
}

Copilot uses AI. Check for mistakes.

var targetClass = (values.get(0) instanceof Map) ? null : values.get(0).getClass();
var value = parseKeyValue(keyWithoutPrefix(valueEntry.getKey()), targetClass, objectMapper);
valueList.add(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@ void setup() {
when(mockedContext.getControllerConfiguration()).thenReturn(controllerConfiguration);
}

@Test
void statefulSetWithMissingManagedField() {
var actual = loadResource("statefulset-with-managed-fields-missing.yaml", StatefulSet.class);
var desired =
actual
.edit()
.editMetadata()
.withManagedFields(List.of())
.endMetadata()
.editSpec()
.editTemplate()
.editSpec()
.editFirstContainer()
.withImage("new")
.endContainer()
.endSpec()
.endTemplate()
.endSpec()
.build();

assertThat(matcher.matches(actual, desired, mockedContext)).isFalse();
}

@Test
void noMatchWhenNoMatchingController() {
var desired = loadResource("nginx-deployment.yaml", Deployment.class);
Expand Down
Loading