8194230: jdk/internal/jrtfs/remote/RemoteRuntimeImageTest.java fails with java.lang.NullPointerException
authorxiaofeya
Tue, 14 Aug 2018 10:42:00 +0800
changeset 51392 523f58763da6
parent 51391 07ea887eee5f
child 51393 cc8d309cd05a
8194230: jdk/internal/jrtfs/remote/RemoteRuntimeImageTest.java fails with java.lang.NullPointerException Reviewed-by: mchung
test/jdk/jdk/internal/jrtfs/remote/RemoteRuntimeImageTest.java
--- a/test/jdk/jdk/internal/jrtfs/remote/RemoteRuntimeImageTest.java	Mon Aug 13 17:39:27 2018 -0700
+++ b/test/jdk/jdk/internal/jrtfs/remote/RemoteRuntimeImageTest.java	Tue Aug 14 10:42:00 2018 +0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -32,7 +32,6 @@
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.nio.file.FileSystems;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
@@ -55,7 +54,7 @@
             return;
         }
 
-        Path jdk8Path = getJdk8Path(jdk8Home);
+        Path jdk8Path = Paths.get(jdk8Home);
         if (!isJdk8(jdk8Path)) {
             System.err.println("This test is only for JDK 8. Skip testing");
             return;
@@ -102,16 +101,14 @@
         }
     }
 
-    private static Path getJdk8Path(String jdk8Home) {
-        Path jdk8Path = Paths.get(jdk8Home);
-        // It is possible to point to the path of java executable by ${JT_JAVA}
-        return Files.isDirectory(jdk8Path)? jdk8Path : jdk8Path.getParent().getParent();
-    }
-
-    private static boolean isJdk8(Path jdk8Home) throws FileNotFoundException, IOException {
-        File file = jdk8Home.resolve("release").toFile();
+    private static boolean isJdk8(Path jdk8HomePath) throws IOException {
+        File releaseFile = jdk8HomePath.resolve("release").toFile();
+        if (!releaseFile.exists()) {
+            throw new RuntimeException(releaseFile.getPath() +
+                    " doesn't exist");
+        }
         Properties props = new Properties();
-        try (FileInputStream in = new FileInputStream(file)) {
+        try (FileInputStream in = new FileInputStream(releaseFile)) {
             props.load(in);
         }