brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aledsage <...@git.apache.org>
Subject [GitHub] brooklyn-server pull request #521: fix unexpected AddChildrenEffector behavi...
Date Thu, 09 Feb 2017 17:24:18 GMT
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/521#discussion_r100361187
  
    --- Diff: camp/camp-brooklyn/src/main/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslDeferredFunctionCall.java
---
    @@ -99,48 +99,81 @@ public Object call() throws Exception {
         }
     
         protected static Maybe<Object> invokeOn(Object obj, String fnName, List<?>
args) {
    -        Object instance = obj;
    -        List<?> instanceArgs = args;
    -        Maybe<Method> method = Reflections.getMethodFromArgs(instance, fnName,
instanceArgs);
    -
    -        if (method.isAbsent()) {
    +        return new Invoker(obj, fnName, args).invoke();
    +    }
    +    
    +    protected static class Invoker {
    +        final Object obj;
    +        final String fnName;
    +        final List<?> args;
    +        
    +        Maybe<Method> method;
    +        Object instance;
    +        List<?> instanceArgs;
    +        
    +        protected Invoker(Object obj, String fnName, List<?> args) {
    +            this.fnName = fnName;
    +            this.obj = obj;
    +            this.args = args;
    +        }
    +        
    +        protected Maybe<Object> invoke() {
    +            findMethod();
    +            
    +            if (method.isPresent()) {
    +                Method m = method.get();
    +    
    +                checkCallAllowed(m);
    +    
    +                try {
    +                    // Value is most likely another BrooklynDslDeferredSupplier - let
the caller handle it,
    +                    return Maybe.of(Reflections.invokeMethodFromArgs(instance, m, instanceArgs));
    +                } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException
e) {
    +                    // If the method is there but not executable for whatever reason
fail with a fatal error, don't return an absent.
    +                    throw Exceptions.propagate(new InvocationTargetException(e, "Error
invoking '"+fnName+instanceArgs+"' on '"+instance+"'"));
    --- End diff --
    
    Minor: I don't think this should be an `InvocationTargetException` - `e` was not "thrown
by an invoked method or constructor". If `e` is an IllegalArgumentException or IllegalAccessException,
then it was caused by trying to invoke it; if `e` is an `InvocationTargetException` then it
is already wrapped. We probably just want `Exceptions.propagateAnnotated("...", e)`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message