Commit ebf3b473 authored by Andy Wilkinson's avatar Andy Wilkinson

Make ExtendedGroovyClassLoader compatible with Java 9

Closes gh-10445
parent bec2e97b
...@@ -175,7 +175,8 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader { ...@@ -175,7 +175,8 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
DefaultScopeParentClassLoader(ClassLoader parent) { DefaultScopeParentClassLoader(ClassLoader parent) {
super(parent); super(parent);
this.groovyOnlyClassLoader = new URLClassLoader(getGroovyJars(parent), null); this.groovyOnlyClassLoader = new URLClassLoader(getGroovyJars(parent),
parent.getParent());
} }
private URL[] getGroovyJars(final ClassLoader parent) { private URL[] getGroovyJars(final ClassLoader parent) {
...@@ -232,7 +233,9 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader { ...@@ -232,7 +233,9 @@ public class ExtendedGroovyClassLoader extends GroovyClassLoader {
@Override @Override
protected Class<?> loadClass(String name, boolean resolve) protected Class<?> loadClass(String name, boolean resolve)
throws ClassNotFoundException { throws ClassNotFoundException {
this.groovyOnlyClassLoader.loadClass(name); if (!name.startsWith("java.")) {
this.groovyOnlyClassLoader.loadClass(name);
}
return super.loadClass(name, resolve); return super.loadClass(name, resolve);
} }
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -64,4 +64,10 @@ public class ExtendedGroovyClassLoaderTests { ...@@ -64,4 +64,10 @@ public class ExtendedGroovyClassLoaderTests {
this.defaultScopeGroovyClassLoader.loadClass("java.lang.Boolean"); this.defaultScopeGroovyClassLoader.loadClass("java.lang.Boolean");
} }
@Test
public void loadsSqlTypes() throws Exception {
this.contextClassLoader.loadClass("java.sql.SQLException");
this.defaultScopeGroovyClassLoader.loadClass("java.sql.SQLException");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment