Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Only call URL.setURLStreamHandlerFactory once

Calling URL.setURLStreamHandlerFactory a second time causes Java to throw an error.
  • Loading branch information...
commit c6f8eef78bbb9d2eee9e02916e39788598d627f1 1 parent 8794050
@candrews authored
View
9 src/main/java/com/integralblue/httpresponsecache/HttpResponseCache.java
@@ -146,6 +146,8 @@
public final class HttpResponseCache extends ResponseCache
implements Closeable, ExtendedResponseCache {
+ private static boolean calledSetURLStreamHandlerFactory = false;
+
private final com.integralblue.httpresponsecache.compat.libcore.net.http.HttpResponseCache delegate;
private HttpResponseCache(File directory, long maxSize) throws IOException {
@@ -188,8 +190,13 @@ public static HttpResponseCache install(File directory, long maxSize) throws IOE
HttpResponseCache result = new HttpResponseCache(directory, maxSize);
ResponseCache.setDefault(result);
- URL.setURLStreamHandlerFactory(new URLStreamHandlerFactoryImpl());
HttpsURLConnection.setDefaultHostnameVerifier(new DefaultHostnameVerifier());
+ if(!calledSetURLStreamHandlerFactory) {
+ // The stream handler factory can only be set once, so don't set it again if it's already been set
+ // This can happen if the application calls install() then delete() then install() again
+ calledSetURLStreamHandlerFactory = true;
+ URL.setURLStreamHandlerFactory(new URLStreamHandlerFactoryImpl());
+ }
return result;
}
Please sign in to comment.
Something went wrong with that request. Please try again.