Skip to content

Commit cd54c96

Browse files
committed
Add comment explaining lazy declared versions
A recent change moved computing declared versions from using reflection which occurred repeatedly to a lazily-initialized holder so that declared versions are computed exactly once. This commit adds a comment explaining the motivation for this change.
1 parent 452bfc0 commit cd54c96

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

server/src/main/java/org/elasticsearch/Version.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ public class Version implements Comparable<Version> {
163163
+ org.apache.lucene.util.Version.LATEST + "] is still set to [" + CURRENT.luceneVersion + "]";
164164
}
165165

166-
private static class DeclaredVersionsHolder {
167-
static final List<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class));
168-
}
169-
170166
public static Version readVersion(StreamInput in) throws IOException {
171167
return fromId(in.readVInt());
172168
}
@@ -406,6 +402,15 @@ public int compareTo(Version other) {
406402
return Integer.compare(this.id, other.id);
407403
}
408404

405+
/*
406+
* We need the declared versions when computing the minimum compatibility version. As computing the declared versions uses reflection it
407+
* is not cheap. Since computing the minimum compatibility version can occur often, we use this holder to compute the declared versions
408+
* lazily once.
409+
*/
410+
private static class DeclaredVersionsHolder {
411+
static final List<Version> DECLARED_VERSIONS = Collections.unmodifiableList(getDeclaredVersions(Version.class));
412+
}
413+
409414
/**
410415
* Returns the minimum compatible version based on the current
411416
* version. Ie a node needs to have at least the return version in order

0 commit comments

Comments
 (0)