Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1FE1F200C16 for ; Thu, 9 Feb 2017 18:24:20 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1E790160B4B; Thu, 9 Feb 2017 17:24:20 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 69BE1160B50 for ; Thu, 9 Feb 2017 18:24:19 +0100 (CET) Received: (qmail 93186 invoked by uid 500); 9 Feb 2017 17:24:18 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 93174 invoked by uid 99); 9 Feb 2017 17:24:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 09 Feb 2017 17:24:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 43C16DFC47; Thu, 9 Feb 2017 17:24:18 +0000 (UTC) From: aledsage To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request #521: fix unexpected AddChildrenEffector behavi... Content-Type: text/plain Message-Id: <20170209172418.43C16DFC47@git1-us-west.apache.org> Date: Thu, 9 Feb 2017 17:24:18 +0000 (UTC) archived-at: Thu, 09 Feb 2017 17:24:20 -0000 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 invokeOn(Object obj, String fnName, List args) { - Object instance = obj; - List instanceArgs = args; - Maybe 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; + Object instance; + List instanceArgs; + + protected Invoker(Object obj, String fnName, List args) { + this.fnName = fnName; + this.obj = obj; + this.args = args; + } + + protected Maybe 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. ---