Skip to content

Commit 8e5372a

Browse files
author
Max Hniebergall
committed
Fix NPE by getting request once and defaulting to empty list
1 parent 745950b commit 8e5372a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

x-pack/plugin/inference/qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/xpack/application/OpenAiServiceUpgradeIT.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import org.junit.BeforeClass;
1717

1818
import java.io.IOException;
19+
import java.util.Collection;
20+
import java.util.LinkedList;
1921
import java.util.List;
2022
import java.util.Map;
2123

@@ -139,9 +141,11 @@ public void testOpenAiCompletions() throws IOException {
139141

140142
assertCompletionInference(oldClusterId);
141143
} else if (isMixedCluster()) {
142-
var configs = (List<Map<String, Object>>) get(testTaskType, oldClusterId).get("endpoints");
144+
List<Map<String, Object>> configs = new LinkedList<>();
145+
var request = get(testTaskType, oldClusterId);
146+
configs.addAll((Collection<? extends Map<String, Object>>) request.getOrDefault("endpoints", List.of()));
143147
if (oldClusterHasFeature("gte_v" + MODELS_RENAMED_TO_ENDPOINTS) == false) {
144-
configs.addAll((List<Map<String, Object>>) get(testTaskType, oldClusterId).get(old_cluster_endpoint_identifier));
148+
configs.addAll((List<Map<String, Object>>) request.getOrDefault(old_cluster_endpoint_identifier, List.of()));
145149
// in version 8.15, there was a breaking change where "models" was renamed to "endpoints"
146150
}
147151
assertEquals("openai", configs.get(0).get("service"));

0 commit comments

Comments
 (0)