Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FIXED JENKINS-39159] If we create a URLClassLoader we should also cl…
…ose it.
  • Loading branch information
jglick committed Feb 6, 2017
1 parent 252e639 commit 4e35651
Showing 1 changed file with 17 additions and 10 deletions.
Expand Up @@ -145,6 +145,7 @@ public Object evaluate(ClassLoader loader, Binding binding) throws Exception {
if (!calledConfiguring) {
throw new IllegalStateException("you need to call configuring or a related method before using GroovyScript");
}
URLClassLoader urlcl = null;
List<ClasspathEntry> cp = getClasspath();
if (!cp.isEmpty()) {
List<URL> urlList = new ArrayList<URL>(cp.size());
Expand All @@ -154,18 +155,24 @@ public Object evaluate(ClassLoader loader, Binding binding) throws Exception {
urlList.add(entry.getURL());
}

loader = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), loader);
loader = urlcl = new URLClassLoader(urlList.toArray(new URL[urlList.size()]), loader);
}
loader = GroovySandbox.createSecureClassLoader(loader);
if (sandbox) {
GroovyShell shell = new GroovyShell(loader, binding, GroovySandbox.createSecureCompilerConfiguration());
try {
return GroovySandbox.run(shell.parse(script), Whitelist.all());
} catch (RejectedAccessException x) {
throw ScriptApproval.get().accessRejected(x, ApprovalContext.create());
try {
loader = GroovySandbox.createSecureClassLoader(loader);
if (sandbox) {
GroovyShell shell = new GroovyShell(loader, binding, GroovySandbox.createSecureCompilerConfiguration());
try {
return GroovySandbox.run(shell.parse(script), Whitelist.all());
} catch (RejectedAccessException x) {
throw ScriptApproval.get().accessRejected(x, ApprovalContext.create());
}
} else {
return new GroovyShell(loader, binding).evaluate(ScriptApproval.get().using(script, GroovyLanguage.get()));
}
} finally {
if (urlcl != null) {
urlcl.close();
}
} else {
return new GroovyShell(loader, binding).evaluate(ScriptApproval.get().using(script, GroovyLanguage.get()));
}
}

Expand Down

0 comments on commit 4e35651

Please sign in to comment.