Repository: ignite Updated Branches: refs/heads/ignite-2.7 fe3ab2881 -> 887139a5c
IGNITE-8146: Adopted IgniteUtils classLoaderUrls() for JDK 9+. This closes #4826. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/1c2bb5c0 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/1c2bb5c0 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/1c2bb5c0 Branch: refs/heads/ignite-2.7 Commit: 1c2bb5c050b04b089c2b76c2a869bf1b5bbe5e63 Parents: fe3ab28 Author: tledkov-gridgain <tled...@gridgain.com> Authored: Thu Sep 27 16:08:49 2018 +0300 Committer: devozerov <voze...@gridgain.com> Committed: Thu Sep 27 16:22:38 2018 +0300 ---------------------------------------------------------------------- .../ignite/internal/util/IgniteUtils.java | 43 +++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/1c2bb5c0/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java index c5054ad..b8ba742 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java @@ -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()); + } + finally { + // Recover accessible field state. + if (!accessible) + urlClsLdrField.setAccessible(false); + } + } } - catch (IllegalAccessException e) { + catch (InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(System.err); + return EMPTY_URL_ARR; } }