From 12cd5e914608de3ef94b591fb6971ec4206bac99 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Mon, 30 Nov 2015 09:15:38 +0100 Subject: [PATCH] Fix quality flaws in BatchUtils --- .../src/main/java/org/sonar/batch/util/BatchUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java index aa5fbc35ae0..1315cd1d4fb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java +++ b/sonar-batch/src/main/java/org/sonar/batch/util/BatchUtils.java @@ -27,7 +27,9 @@ import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; +import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,13 +70,14 @@ public class BatchUtils { return o.getClass().getName(); } + @CheckForNull public static String getServerVersion() { - InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("sq-version.txt"); + InputStream is = BatchUtils.class.getResourceAsStream("/sq-version.txt"); if (is == null) { LOG.warn("Failed to get SQ version"); return null; } - try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { + try (BufferedReader br = IOUtils.toBufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) { return br.readLine(); } catch (IOException e) { LOG.warn("Failed to get SQ version", e); -- 2.39.5