Bug 529172 - [9] Runnable Jar including Sqlite JDBC doesn't...

Use reflection to know if we can call
ClassLoader.getPlatformClassLoader() (only on Java9) to get a
parent ClassLoader for our URLClassLoader with access to restricted
package names or not

Change-Id: I623c54b7d83fe07b556e9d71c9f303a98d3c73fd
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=529172
Signed-off-by: Guille <ggalmazor@gmail.com>
diff --git a/org.eclipse.jdt.ui/jar in jar loader/org/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader.java b/org.eclipse.jdt.ui/jar in jar loader/org/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader.java
index 7a51acd..0b7bbcc 100644
--- a/org.eclipse.jdt.ui/jar in jar loader/org/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader.java
+++ b/org.eclipse.jdt.ui/jar in jar loader/org/eclipse/jdt/internal/jarinjarloader/JarRsrcLoader.java
@@ -51,13 +51,28 @@
 			else
 				rsrcUrls[i] = new URL(JIJConstants.JAR_INTERNAL_URL_PROTOCOL_WITH_COLON + rsrcPath + JIJConstants.JAR_INTERNAL_SEPARATOR);    
 		}
-		ClassLoader jceClassLoader = new URLClassLoader(rsrcUrls, null);
+		ClassLoader jceClassLoader = new URLClassLoader(rsrcUrls, getParentClassLoader());
 		Thread.currentThread().setContextClassLoader(jceClassLoader);
 		Class c = Class.forName(mi.rsrcMainClass, true, jceClassLoader);
 		Method main = c.getMethod(JIJConstants.MAIN_METHOD_NAME, new Class[]{args.getClass()}); 
 		main.invoke((Object)null, new Object[]{args});
 	}
 
+	private static ClassLoader getParentClassLoader() throws InvocationTargetException, IllegalAccessException {
+		// On Java8, it is ok to use a null parent class loader, but, starting with Java 9,
+		// we need to provide one that has access to the restricted list of packages that
+		// otherwise would produce a SecurityException when loaded
+		try {
+			// We use reflection here because the method ClassLoader.getPlatformClassLoader()
+			// is only present starting from Java 9
+			Method platformClassLoader = ClassLoader.class.getMethod("getPlatformClassLoader");
+			return (ClassLoader) platformClassLoader.invoke(null);
+		} catch (NoSuchMethodException e) {
+			// This is a safe value to be used on Java 8 an previous versions
+			return null;
+		}
+	}
+
 	private static ManifestInfo getManifestInfo() throws IOException {
 		Enumeration resEnum;
 		resEnum = Thread.currentThread().getContextClassLoader().getResources(JarFile.MANIFEST_NAME);