diff --git a/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java b/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java index 280345e0c8..8d94c3e889 100644 --- a/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java +++ b/core/src/main/java/org/jclouds/rest/internal/DelegatesToInvocationFunction.java @@ -141,7 +141,7 @@ public class DelegatesToInvocationFunction invokable = invocation.getInvokable(); - if (CLOSE.equals(invokable)) { + if (isCloseMethod(invokable)) { try { injector.getInstance(Closer.class).close(); return null; @@ -157,6 +157,22 @@ public class DelegatesToInvocationFunction invokable) { + /* + * Tests equality according to the Javadoc for java.lang.reflect.Method: + * + * Two Methods are the same if they were declared by the same class + * and have the same name and formal parameter types and return type. + * + * Invokable now uses the *owning* class (not the declaring class) in + * its equals check. + */ + return CLOSE.getDeclaringClass().equals(invokable.getDeclaringClass()) + && CLOSE.getName().equals(invokable.getName()) + && CLOSE.getParameters().equals(invokable.getParameters()) + && CLOSE.getReturnType().equals(invokable.getReturnType()); + } + protected final Injector injector; protected final TypeToken ownerType; protected final SetCaller setCaller;