Skip to content

Commit 5e1c859

Browse files
authored
Fix off-by-one error in TransportVersionUtils.getNextVersion (#93775)
1 parent a7666a2 commit 5e1c859

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public static TransportVersion getPreviousVersion(TransportVersion version) {
8686
// version does not exist - need the item before the index this version should be inserted
8787
place = -(place + 1);
8888
}
89-
if (place <= 1) {
89+
90+
if (place < 1) {
9091
throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]");
9192
}
9293
return ALL_VERSIONS.get(place - 1);
@@ -97,11 +98,15 @@ public static TransportVersion getNextVersion(TransportVersion version) {
9798
if (place < 0) {
9899
// version does not exist - need the item at the index this version should be inserted
99100
place = -(place + 1);
101+
} else {
102+
// need the *next* version
103+
place++;
100104
}
101-
if (place <= 1) {
105+
106+
if (place < 0 || place >= ALL_VERSIONS.size()) {
102107
throw new IllegalArgumentException("couldn't find any released versions after [" + version + "]");
103108
}
104-
return ALL_VERSIONS.get(place + 1);
109+
return ALL_VERSIONS.get(place);
105110
}
106111

107112
/** Returns a random {@link Version} from all available versions, that is compatible with the given version. */

0 commit comments

Comments
 (0)