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
This commit is contained in:
parent
aa66d5dfb8
commit
7f0048a899
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue