From 8c0dff55906891cc71201de06fb4463557ab72fb Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 12 Apr 2017 23:22:43 -0700 Subject: [PATCH] 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 --- core/src/main/java/org/elasticsearch/Build.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/Build.java b/core/src/main/java/org/elasticsearch/Build.java index c59cdf29e930f..0987c5cd8a4ef 100644 --- a/core/src/main/java/org/elasticsearch/Build.java +++ b/core/src/main/java/org/elasticsearch/Build.java @@ -42,8 +42,10 @@ public class Build { final String date; final boolean isSnapshot; + final String esPrefix = "elasticsearch-" + Version.CURRENT; final URL url = getElasticsearchCodebase(); - if (url.toString().endsWith(".jar")) { + final String urlStr = url.toString(); + if (urlStr.startsWith("file:/") && (urlStr.endsWith(esPrefix + ".jar") || urlStr.endsWith(esPrefix + "-SNAPSHOT.jar"))) { try (JarInputStream jar = new JarInputStream(url.openStream())) { Manifest manifest = jar.getManifest(); shortHash = manifest.getMainAttributes().getValue("Change"); @@ -53,7 +55,7 @@ public class Build { throw new RuntimeException(e); } } else { - // not running from a jar (unit tests, IDE) + // not running from the official elasticsearch jar file (unit tests, IDE, uber client jar, shadiness) shortHash = "Unknown"; date = "Unknown"; isSnapshot = true;