Commit 7f0048a8 authored by Phillip Webb's avatar Phillip Webb

Use fast exceptions when enumerating resources

Update the `LaunchedURLClassLoader` used for fat jar support so that
each iteration on a `findResources` result also allows for fast
exceptions.

Fixes gh-11406
parent aa66d5df
......@@ -65,7 +65,7 @@ public class LaunchedURLClassLoader extends URLClassLoader {
public Enumeration<URL> findResources(String name) throws IOException {
Handler.setUseFastConnectionExceptions(true);
try {
return super.findResources(name);
return new UseFastConnectionExceptionsEnumeration(super.findResources(name));
}
finally {
Handler.setUseFastConnectionExceptions(false);
......@@ -182,4 +182,38 @@ public class LaunchedURLClassLoader extends URLClassLoader {
}
}
private static class UseFastConnectionExceptionsEnumeration
implements Enumeration<URL> {
private final Enumeration<URL> delegate;
UseFastConnectionExceptionsEnumeration(Enumeration<URL> delegate) {
this.delegate = delegate;
}
@Override
public boolean hasMoreElements() {
Handler.setUseFastConnectionExceptions(true);
try {
return this.delegate.hasMoreElements();
}
finally {
Handler.setUseFastConnectionExceptions(false);
}
}
@Override
public URL nextElement() {
Handler.setUseFastConnectionExceptions(true);
try {
return this.delegate.nextElement();
}
finally {
Handler.setUseFastConnectionExceptions(false);
}
}
}
}
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