Make SingleFeatureTest getKarafDistroVersion() throw clear IOException 13/51413/1
authorMichael Vorburger <vorburger@redhat.com>
Fri, 3 Feb 2017 16:17:06 +0000 (17:17 +0100)
committerMichael Vorburger <vorburger@redhat.com>
Fri, 3 Feb 2017 16:17:06 +0000 (17:17 +0100)
instead of a confusion NullPointerException, as e.g. on
https://jenkins.opendaylight.org/releng/job/odlparent-distribution-check-boron/27/console
(and I've seen this before... even on master, not just stable/boron)

Change-Id: I256fccc5a48444c4c8f79a90e129d3641779f45a
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
features-test/src/main/java/org/opendaylight/odlparent/featuretest/SingleFeatureTest.java
features4-test/src/main/java/org/opendaylight/odlparent/featuretest/SingleFeatureTest.java

index aae5b19edfc2017a26289d69fdf143ed1da11133..4f9010f97803abbb330748cd8988e8f900eb1fa3 100644 (file)
@@ -217,16 +217,18 @@ public class SingleFeatureTest {
         }
     }
 
-    private String getKarafVersion() {
+    private String getKarafVersion() throws IOException {
         if (karafVersion == null) {
             // We use a properties file to retrieve ${karaf.version}, instead of .versionAsInProject()
             // This avoids forcing all users to depend on Karaf in their POMs
             Properties singleFeatureTestProps = new Properties();
             try (InputStream singleFeatureTestInputStream = Thread.currentThread().getContextClassLoader()
                     .getResourceAsStream(PROPERTIES_FILENAME)) {
+                if (singleFeatureTestInputStream == null) {
+                    throw new IOException("Resource not found; expected to be present on current thread classloader: "
+                            + PROPERTIES_FILENAME);
+                }
                 singleFeatureTestProps.load(singleFeatureTestInputStream);
-            } catch (IOException e) {
-                LOG.error("Unable to load {} to determine the Karaf version", PROPERTIES_FILENAME, e);
             }
             karafVersion = singleFeatureTestProps.getProperty(KARAF_DISTRO_VERSION_PROP);
 
@@ -238,7 +240,7 @@ public class SingleFeatureTest {
         return karafVersion;
     }
 
-    private String getKarafDistroVersion() {
+    private String getKarafDistroVersion() throws IOException {
         if (karafDistroVersion == null) {
             karafDistroVersion = System.getProperty(KARAF_DISTRO_VERSION_PROP);
             if (karafDistroVersion == null) {
@@ -269,7 +271,7 @@ public class SingleFeatureTest {
                 mvnRepoLocal);
     }
 
-    protected Option getKarafDistroOption() {
+    protected Option getKarafDistroOption() throws IOException {
         String groupId = System.getProperty(KARAF_DISTRO_GROUPID_PROP, KARAF_DISTRO_GROUPID);
         String artifactId = System.getProperty(KARAF_DISTRO_ARTIFACTID_PROP, KARAF_DISTRO_ARTIFACTID);
         String type = System.getProperty(KARAF_DISTRO_TYPE_PROP, KARAF_DISTRO_TYPE);
index 827e5629266978bf50c87e5b4ab94c8efebd9db8..bff755d3ef33224440fc659cbc5ed0c2bca00dc7 100644 (file)
@@ -199,16 +199,18 @@ public class SingleFeatureTest {
         return File.createTempFile("SingleFeatureTest-Karaf-JavaFlightRecorder", ".jfr").getAbsolutePath();
     }
 
-    private String getKarafVersion() {
+    private String getKarafVersion() throws IOException {
         if (karafVersion == null) {
             // We use a properties file to retrieve ${karaf.version}, instead of .versionAsInProject()
             // This avoids forcing all users to depend on Karaf in their POMs
             Properties singleFeatureTestProps = new Properties();
             try (InputStream singleFeatureTestInputStream = Thread.currentThread().getContextClassLoader()
                     .getResourceAsStream(PROPERTIES_FILENAME)) {
+                if (singleFeatureTestInputStream == null) {
+                    throw new IOException("Resource not found; expected to be present on current thread classloader: "
+                            + PROPERTIES_FILENAME);
+                }
                 singleFeatureTestProps.load(singleFeatureTestInputStream);
-            } catch (IOException e) {
-                LOG.error("Unable to load {} to determine the Karaf version", PROPERTIES_FILENAME, e);
             }
             karafVersion = singleFeatureTestProps.getProperty(KARAF_DISTRO_VERSION_PROP);
 
@@ -220,7 +222,7 @@ public class SingleFeatureTest {
         return karafVersion;
     }
 
-    private String getKarafDistroVersion() {
+    private String getKarafDistroVersion() throws IOException {
         if (karafDistroVersion == null) {
             karafDistroVersion = System.getProperty(KARAF_DISTRO_VERSION_PROP);
             if (karafDistroVersion == null) {
@@ -251,7 +253,7 @@ public class SingleFeatureTest {
                 mvnRepoLocal);
     }
 
-    protected Option getKarafDistroOption() {
+    protected Option getKarafDistroOption() throws IOException {
         String groupId = System.getProperty(KARAF_DISTRO_GROUPID_PROP, KARAF_DISTRO_GROUPID);
         String artifactId = System.getProperty(KARAF_DISTRO_ARTIFACTID_PROP, KARAF_DISTRO_ARTIFACTID);
         String type = System.getProperty(KARAF_DISTRO_TYPE_PROP, KARAF_DISTRO_TYPE);