added temporary workaround for AutoCloseable which will be deleted in jclouds 1.7

This commit is contained in:
adriancole 2013-04-08 16:58:36 -07:00
parent 88871c9fe9
commit 8f68de0018
1 changed files with 17 additions and 1 deletions

View File

@ -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<?, ?>, 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.
*
* <h4>note</h4>
*
* 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...)}
*/