Skip to content

Commit 45e07c2

Browse files
author
CVE Bot
committed
fix: handle empty BWC versions stream in AbstractYamlRestCompatTestPlugin
When building an elasticsearch docker image without the full BWC version checkout (e.g. the upgrade-elasticsearch workflow), getBwcVersions().getUnreleased() may return an empty list for the previous major version (getMajor() == currentMajor-1). The call to .min().get() on an empty stream throws NoSuchElementException 'No value present'. Fix by using .orElse(null) and returning early when no compatible BWC version is found.
1 parent e31282d commit 45e07c2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/compat/compat/AbstractYamlRestCompatTestPlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ public void apply(Project project) {
117117
.stream()
118118
.filter(v -> v.getMajor() == currentMajor - 1)
119119
.min(Comparator.reverseOrder())
120-
.get();
120+
.orElse(null);
121+
// If no unreleased previous-major versions exist, REST compat testing is not applicable
122+
// (e.g. building a standalone docker image export without BWC version checkout)
123+
if (lastMinor == null) {
124+
return;
125+
}
121126
String lastMinorProjectPath = buildParams.getBwcVersions().unreleasedInfo(lastMinor).gradleProjectPath();
122127

123128
// copy compatible rest specs

0 commit comments

Comments
 (0)