浏览代码

Fix off-by-one error in TransportVersionUtils.getNextVersion (#93775)

Simon Cooper 2 年之前
父节点
当前提交
5e1c859dc8
共有 1 个文件被更改,包括 8 次插入3 次删除
  1. 8 3
      test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java

+ 8 - 3
test/framework/src/main/java/org/elasticsearch/test/TransportVersionUtils.java

@@ -86,7 +86,8 @@ public class TransportVersionUtils {
             // version does not exist - need the item before the index this version should be inserted
             // version does not exist - need the item before the index this version should be inserted
             place = -(place + 1);
             place = -(place + 1);
         }
         }
-        if (place <= 1) {
+
+        if (place < 1) {
             throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]");
             throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]");
         }
         }
         return ALL_VERSIONS.get(place - 1);
         return ALL_VERSIONS.get(place - 1);
@@ -97,11 +98,15 @@ public class TransportVersionUtils {
         if (place < 0) {
         if (place < 0) {
             // version does not exist - need the item at the index this version should be inserted
             // version does not exist - need the item at the index this version should be inserted
             place = -(place + 1);
             place = -(place + 1);
+        } else {
+            // need the *next* version
+            place++;
         }
         }
-        if (place <= 1) {
+
+        if (place < 0 || place >= ALL_VERSIONS.size()) {
             throw new IllegalArgumentException("couldn't find any released versions after [" + version + "]");
             throw new IllegalArgumentException("couldn't find any released versions after [" + version + "]");
         }
         }
-        return ALL_VERSIONS.get(place + 1);
+        return ALL_VERSIONS.get(place);
     }
     }
 
 
     /** Returns a random {@link Version} from all available versions, that is compatible with the given version. */
     /** Returns a random {@link Version} from all available versions, that is compatible with the given version. */