From 8f68de0018811c4ced47535fed437dde2d566c4d Mon Sep 17 00:00:00 2001 From: adriancole Date: Mon, 8 Apr 2013 16:58:36 -0700 Subject: [PATCH] added temporary workaround for AutoCloseable which will be deleted in jclouds 1.7 --- .../org/jclouds/rest/config/RestModule.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/jclouds/rest/config/RestModule.java b/core/src/main/java/org/jclouds/rest/config/RestModule.java index e4819c8b44..db7f67b07a 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestModule.java @@ -27,6 +27,7 @@ import static org.jclouds.reflect.Reflection2.method; import static org.jclouds.reflect.Reflection2.methods; import static org.jclouds.rest.config.BinderUtils.bindHttpApi; +import java.io.Closeable; import java.net.Proxy; import java.net.URI; import java.util.Map; @@ -120,12 +121,27 @@ public class RestModule extends AbstractModule { public static void putInvokables(Class sync, Class async, Cache, Invokable> cache) { for (Invokable invoked : methods(sync)) { Invokable delegatedMethod = method(async, invoked.getName(), getParameterTypes(invoked)); - checkArgument(delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()), + checkArgument( + delegatedMethod.getExceptionTypes().equals(invoked.getExceptionTypes()) || isCloseable(delegatedMethod), "invoked %s has different typed exceptions than target %s", invoked, delegatedMethod); cache.put(invoked, delegatedMethod); } } + /** + * In JDK7 Closeable.close is declared in AutoCloseable, which throws + * Exception vs IOException, so we have to be more lenient about exception + * type declarations. + * + *

note

+ * + * This will be refactored out when we delete Async code in jclouds 1.7. + */ + private static boolean isCloseable(Invokable delegatedMethod) { + return "close".equals(delegatedMethod.getName()) + && Closeable.class.isAssignableFrom(delegatedMethod.getDeclaringClass()); + } + /** * for portability with {@link Class#getMethod(String, Class...)} */