Adopted IgniteUtils classLoaderUrls() for JDK 9+. This closes
@@ -552,6 +552,12 @@ public abstract class IgniteUtils {
private static boolean devOnlyLogDisabled =
IgniteSystemProperties.getBoolean(IgniteSystemProperties.IGNITE_DEV_ONLY_LOGGING_DISABLED);
+ /** JDK9: jdk.internal.loader.URLClassPath. */
+ private static Class clsURLClassPath;
+
+ /** JDK9: URLClassPath#getURLs. */
+ private static Method mthdURLClassPathGetUrls;
+
/*
* Initializes enterprise check.
*/
@@ -804,6 +810,15 @@ public abstract class IgniteUtils {
else if ("toString".equals(mtd.getName()))
toStringMtd = mtd;
}
+
+ try {
+ clsURLClassPath = Class.forName("jdk.internal.loader.URLClassPath");
+ mthdURLClassPathGetUrls = clsURLClassPath.getMethod("getURLs");
+ }
+ catch (ReflectiveOperationException e) {
+ clsURLClassPath = null;
+ mthdURLClassPathGetUrls = null;
+ }
}
/**
@@ -7673,9 +7688,33 @@ public abstract class IgniteUtils {
return ((URLClassLoader)clsLdr).getURLs();
else if (bltClsLdrCls != null && urlClsLdrField != null && bltClsLdrCls.isAssignableFrom(clsLdr.getClass())) {
try {
- return ((URLClassLoader)urlClsLdrField.get(clsLdr)).getURLs();
+ synchronized (urlClsLdrField) {
+ // Backup accessible field state.
+ boolean accessible = urlClsLdrField.isAccessible();
+
+ try {
+ if (!accessible)
+ urlClsLdrField.setAccessible(true);
+
+ Object ucp = urlClsLdrField.get(clsLdr);
+
+ if (ucp instanceof URLClassLoader)
+ return ((URLClassLoader)ucp).getURLs();
+ else if (clsURLClassPath!= null && clsURLClassPath.isInstance(ucp))
+ return (URL[])mthdURLClassPathGetUrls.invoke(ucp);
+ else
+ throw new RuntimeException("Unknown classloader: " + clsLdr.getClass());
}
- catch (IllegalAccessException e) {
+ finally {
+ // Recover accessible field state.
+ if (!accessible)
+ urlClsLdrField.setAccessible(false);
+ }
+ }
+ }
+ catch (InvocationTargetException | IllegalAccessException e) {
+ e.printStackTrace(System.err);
+
return EMPTY_URL_ARR;
}
}
