Skip to content

Commit 8be1c85

Browse files
committed
Restrict build info loading to ES jar, not any jar (#24049)
This change makes the build info initialization only try to load a jar manifest if it is the elasticsearch jar. Anything else (eg a repackaged ES for use of transport client in an uber jar) will contain "Unknown" for the build info as it does for tests currently. fixes #21955
1 parent 54a7249 commit 8be1c85

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/src/main/java/org/elasticsearch/Build.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ public class Build {
4242
final String date;
4343
final boolean isSnapshot;
4444

45+
final String esPrefix = "elasticsearch-" + Version.CURRENT;
4546
final URL url = getElasticsearchCodebase();
46-
if (url.toString().endsWith(".jar")) {
47+
final String urlStr = url.toString();
48+
if (urlStr.startsWith("file:/") && (urlStr.endsWith(esPrefix + ".jar") || urlStr.endsWith(esPrefix + "-SNAPSHOT.jar"))) {
4749
try (JarInputStream jar = new JarInputStream(url.openStream())) {
4850
Manifest manifest = jar.getManifest();
4951
shortHash = manifest.getMainAttributes().getValue("Change");
@@ -53,7 +55,7 @@ public class Build {
5355
throw new RuntimeException(e);
5456
}
5557
} else {
56-
// not running from a jar (unit tests, IDE)
58+
// not running from the official elasticsearch jar file (unit tests, IDE, uber client jar, shadiness)
5759
shortHash = "Unknown";
5860
date = "Unknown";
5961
isSnapshot = true;

0 commit comments

Comments
 (0)