groovy.lang.MissingMethodException Java Examples

The following examples show how to use groovy.lang.MissingMethodException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InvokerHelper.java    From groovy with Apache License 2.0 6 votes vote down vote up
static Object invokePogoMethod(Object object, String methodName, Object arguments) {
    GroovyObject groovy = (GroovyObject) object;
    boolean intercepting = groovy instanceof GroovyInterceptable;
    try {
        // if it's a pure interceptable object (even intercepting toString(), clone(), ...)
        if (intercepting) {
            return groovy.invokeMethod(methodName, asUnwrappedArray(arguments));
        }
        //else try a statically typed method or a GDK method
        return groovy.getMetaClass().invokeMethod(object, methodName, asArray(arguments));
    } catch (MissingMethodException e) {
        if (e instanceof MissingMethodExecutionFailed) {
            throw (MissingMethodException) e.getCause();
        } else if (!intercepting && e.getMethod().equals(methodName) && object.getClass() == e.getType()) {
            // in case there's nothing else, invoke the object's own invokeMethod()
            return groovy.invokeMethod(methodName, asUnwrappedArray(arguments));
        } else {
            throw e;
        }
    }
}
 
Example #2
Source File: ConfigureUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
Example #3
Source File: ZigbeeConfigContext.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
public void iaszone(ReflexMatchContext ctx, Map<String,Object> config, IasZoneTypes type) {
   int ep = 1;
   int pr = ZigbeeNaming.HA_PROFILE_ID;
   int cl = IasZone.CLUSTER_ID & 0xFFFF;

   if (config.containsKey("endpoint")) {
      ep = ((Number)config.get("endpoint")).intValue();
   }

   if (config.containsKey("profile")) {
      pr = ((Number)config.get("profile")).intValue();
   }

   if (config.containsKey("cluster")) {
      cl = ((Number)config.get("cluster")).intValue();
   }

   switch (type) {
   case ENROLL:
      ctx.addAction(new ReflexActionZigbeeIasZoneEnroll(ep,pr,cl));
      break;

   default:
      throw new MissingMethodException("iaszone", getClass(), new Object[] { type });
   }
}
 
Example #4
Source File: FactoryBuilderSupport.java    From groovy with Apache License 2.0 6 votes vote down vote up
public Object invokeMethod(Object object, String methodName, Object[] arguments) {
    try {
        return delegate.invokeMethod(object, methodName, arguments);
    } catch (MissingMethodException mme) {
        // attempt builder resolution
        try {
            if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
                // dispatch to factories if it is not a literal method
                return builder.invokeMethod(methodName, arguments);
            } else {
                return InvokerHelper.invokeMethod(builder, methodName, arguments);
            }
        } catch (MissingMethodException mme2) {
            // chain secondary exception
            Throwable root = mme;
            while (root.getCause() != null) {
                root = root.getCause();
            }
            root.initCause(mme2);
            // throw original
            throw mme;
        }
    }
}
 
Example #5
Source File: DefaultDependencyHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
Example #6
Source File: PropertyTest.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void testListCoercionPropertyOnJFrame() throws Exception {
    if (HeadlessTestSupport.isHeadless()) return;

    try {
        JFrame bean = new JFrame();
        List list = new ArrayList();
        list.add(Integer.valueOf(10));
        list.add(Integer.valueOf(20));

        InvokerHelper.setProperty(bean, "location", list);
        assertEquals("Should have set a point", new Point(10, 20), bean.getLocation());
    }
    catch (MissingMethodException e) {
        System.out.println("Failed with cause: " + e);
        e.printStackTrace();
        fail("Should not have throw: " + e);
    }
}
 
Example #7
Source File: DefaultDependencyHandler.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
Example #8
Source File: ConfigureUtil.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
Example #9
Source File: FactoryBuilderSupport.java    From groovy with Apache License 2.0 6 votes vote down vote up
public Object invokeMethod(Object object, String methodName, Object arguments) {
    try {
        return delegate.invokeMethod(object, methodName, arguments);
    } catch (MissingMethodException mme) {
        // attempt builder resolution
        try {
            if (builder.getMetaClass().respondsTo(builder, methodName).isEmpty()) {
                // dispatch to factories if it is not a literal method
                return builder.invokeMethod(methodName, arguments);
            } else {
                return InvokerHelper.invokeMethod(builder, methodName, arguments);
            }
        } catch (MissingMethodException mme2) {
            // chain secondary exception
            Throwable root = mme;
            while (root.getCause() != null) {
                root = root.getCause();
            }
            root.initCause(mme2);
            // throw original
            throw mme;
        }
    }
}
 
Example #10
Source File: FactoryBuilderSupport.java    From groovy with Apache License 2.0 6 votes vote down vote up
/**
 * This method is the workhorse of the builder.
 *
 * @param methodName the name of the method being invoked
 * @param name       the name of the node
 * @param args       the arguments passed into the node
 * @return the object from the factory
 */
private Object doInvokeMethod(String methodName, Object name, Object args) {
    Reference explicitResult = new Reference();
    if (checkExplicitMethod(methodName, args, explicitResult)) {
        return explicitResult.get();
    } else {
        try {
            return dispatchNodeCall(name, args);
        } catch(MissingMethodException mme) {
            if(mme.getMethod().equals(methodName) && methodMissingDelegate != null) {
                return methodMissingDelegate.call(methodName, args);
            }
            throw mme;
        }
    }
}
 
Example #11
Source File: CapabilityEnvironmentBinding.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Override
public Object invokeMethod(String name, Object args) {
   try {
      return super.invokeMethod(name, args);
   }
   catch(MissingMethodException e) {
      if(name.startsWith("on")) {
         CapabilityDefinition definition = builder.getCapabilityDefinition();
         if(definition == null) {
            throw new IllegalArgumentException("Must specify the 'capability' header before adding a handler");
         }
         throw new IllegalArgumentException(
               "Invalid handler method [" + name + "], only the capability on" + definition.getCapabilityName() +
               " or one of the events " + toEventNames(definition.getCommands()) + " is valid here"
         );
      }
      throw e;
   }
}
 
Example #12
Source File: NonTransformedModelDslBacking.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Void methodMissing(String name, Object argsObj) {
    Object[] args = (Object[]) argsObj;

    if (!executingDsl.get()) {
        if (name.equals("$")) {
            throw new GradleException(ATTEMPTED_INPUT_SYNTAX_USED_MESSAGE);
        } else {
            throw new MissingMethodException(name, getClass(), args);
        }
    } else {
        if (args.length != 1 || !(args[0] instanceof Closure)) {
            throw new MissingMethodException(name, getClass(), args);
        } else {
            Closure closure = (Closure) args[0];
            getChildPath(name).registerConfigurationAction(closure);
            return null;
        }
    }
}
 
Example #13
Source File: PogoMetaClassSite.java    From groovy with Apache License 2.0 6 votes vote down vote up
public final Object call(final Object receiver, final Object[] args) throws Throwable {
    if (checkCall(receiver)) {
        try {
            try {
                return metaClass.invokeMethod(receiver, name, args);
            } catch (MissingMethodException e) {
                if (e instanceof MissingMethodExecutionFailed) {
                    throw (MissingMethodException)e.getCause();
                } else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
                    // in case there's nothing else, invoke the object's own invokeMethod()
                    return ((GroovyObject)receiver).invokeMethod(name, args);
                } else {
                    throw e;
                }
            }
        } catch (GroovyRuntimeException gre) {
            throw ScriptBytecodeAdapter.unwrap(gre);
        }
    } else {
        return CallSiteArray.defaultCall(this, receiver, args);
    }
}
 
Example #14
Source File: PropertyBinding.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void unbind() {
    if (bound) {
        if (boundToProperty) {
            try {
                InvokerHelper.invokeMethodSafe(boundBean, "removePropertyChangeListener", new Object[]{boundProperty, this});
            } catch (MissingMethodException mme) {
                // ignore, too bad so sad they don't follow conventions, we'll just leave the listener attached
            }
        } else {
            try {
                InvokerHelper.invokeMethodSafe(boundBean, "removePropertyChangeListener", new Object[]{this});
            } catch (MissingMethodException mme2) {
                // ignore, too bad so sad they don't follow conventions, we'll just leave the listener attached
            }
        }
        boundBean = null;
        boundProperty = null;
        bound = false;
    }
}
 
Example #15
Source File: PropertyBinding.java    From groovy with Apache License 2.0 6 votes vote down vote up
public void bind() {
    if (!bound) {
        bound = true;
        boundBean = bean;
        boundProperty = propertyName;
        try {
            InvokerHelper.invokeMethodSafe(boundBean, "addPropertyChangeListener", new Object[]{boundProperty, this});
            boundToProperty = true;
        } catch (MissingMethodException mme) {
            try {
                boundToProperty = false;
                InvokerHelper.invokeMethodSafe(boundBean, "addPropertyChangeListener", new Object[]{this});
            } catch (MissingMethodException mme2) {
                throw new RuntimeException("Properties in beans of type " + bean.getClass().getName() + " are not observable in any capacity (no PropertyChangeListener support).");
            }
        }
    }
}
 
Example #16
Source File: GroovyScriptEngineImpl.java    From groovy with Apache License 2.0 6 votes vote down vote up
private Object invokeImpl(Object thiz, String name, Object... args)
        throws ScriptException, NoSuchMethodException {
    if (name == null) {
        throw new NullPointerException("method name is null");
    }

    try {
        if (thiz != null) {
            return InvokerHelper.invokeMethod(thiz, name, args);
        } else {
            return callGlobal(name, args);
        }
    } catch (MissingMethodException mme) {
        throw new NoSuchMethodException(mme.getMessage());
    } catch (Exception e) {
        throw new ScriptException(e);
    }
}
 
Example #17
Source File: DefaultDependencyHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
Example #18
Source File: DependenciesSettings.java    From gradle-golang-plugin with Mozilla Public License 2.0 6 votes vote down vote up
@Nullable
public Object methodMissing(@Nonnull String name, @Nullable Object args) {
    final Object[] argsArray = (Object[]) args;
    final Configuration configuration = _project.getConfigurations().findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }
    final List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        //noinspection rawtypes
        return doAdd(name, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(name, normalizedArgs.get(0), null);
    } else {
        for (final Object arg : normalizedArgs) {
            doAdd(name, arg, null);
        }
        return null;
    }
}
 
Example #19
Source File: ConfigureUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
Example #20
Source File: ConfigureUtil.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <T> T configureByMap(Map<?, ?> properties, T delegate) {
    DynamicObject dynamicObject = DynamicObjectUtil.asDynamicObject(delegate);

    for (Map.Entry<?, ?> entry : properties.entrySet()) {
        String name = entry.getKey().toString();
        Object value = entry.getValue();

        if (dynamicObject.hasProperty(name)) {
            dynamicObject.setProperty(name, value);
        } else {
            try {
                dynamicObject.invokeMethod(name, value);
            } catch (MissingMethodException e) {
                dynamicObject.setProperty(name, value);
            }
        }
    }

    return delegate;
}
 
Example #21
Source File: DefaultDependencyHandler.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Object methodMissing(String name, Object args) {
    Object[] argsArray = (Object[]) args;
    Configuration configuration = configurationContainer.findByName(name);
    if (configuration == null) {
        throw new MissingMethodException(name, this.getClass(), argsArray);
    }

    List<?> normalizedArgs = CollectionUtils.flattenCollections(argsArray);
    if (normalizedArgs.size() == 2 && normalizedArgs.get(1) instanceof Closure) {
        return doAdd(configuration, normalizedArgs.get(0), (Closure) normalizedArgs.get(1));
    } else if (normalizedArgs.size() == 1) {
        return doAdd(configuration, normalizedArgs.get(0), null);
    } else {
        for (Object arg : normalizedArgs) {
            doAdd(configuration, arg, null);
        }
        return null;
    }
}
 
Example #22
Source File: DelegatingScript.java    From groovy with Apache License 2.0 5 votes vote down vote up
@Override
public Object invokeMethod(String name, Object args) {
    try {
        if (delegate instanceof GroovyObject) {
            return ((GroovyObject) delegate).invokeMethod(name, args);
        }
        return metaClass.invokeMethod(delegate, name, args);
    } catch (MissingMethodException mme) {
        return super.invokeMethod(name, args);
    }
}
 
Example #23
Source File: DefaultConvention.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object invokeMethod(String name, Object... args) {
    if (extensionsStorage.isConfigureExtensionMethod(name, args)) {
        return extensionsStorage.configureExtension(name, args);
    }
    for (Object object : plugins.values()) {
        BeanDynamicObject dynamicObject = new BeanDynamicObject(object);
        if (dynamicObject.hasMethod(name, args)) {
            return dynamicObject.invokeMethod(name, args);
        }
    }
    throw new MissingMethodException(name, Convention.class, args);
}
 
Example #24
Source File: GroovyScriptEngine.java    From james with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeErrorHandler(InformationPoint informationPoint,
                               Method origin,
                               List<RuntimeInformationPointParameter> parameters,
                               Object instance,
                               Thread currentThread,
                               Instant eventTime,
                               Duration executionTime,
                               String[] callStack,
                               Throwable errorCause,
                               CompletableFuture<Object> initialContextProvider) {
    LOG.trace(() -> "Invoking error handler for " + getIdentifier(informationPoint));
    try {
        Stopwatch stopwatch = Stopwatch.createStarted();
        InformationPointHandler handler = createOrGetCachedHandler(informationPoint);
        ErrorHandlerContext handlerContext = new ErrorHandlerContext(
                informationPoint.getClassName(), informationPoint.getMethodName(), origin, parameters, instance,
                currentThread, eventTime, executionTime, callStack, errorCause, initialContextProvider.get());
        handler.invokeMethod(ERROR_HANDLER_FUNCTION, new Object[]{handlerContext});
        stopwatch.stop();
        LOG.trace(() -> "Error handler invocation took " + stopwatch.elapsed());
    } catch (CompilationFailedException cfe) {
        LOG.error(() -> "Script compilation failed when calling error handler for " + getIdentifier(informationPoint), cfe);
    } catch (MissingMethodException mme) {
        LOG.error(() -> "Error handler function missing for " + getIdentifier(informationPoint), mme);
    } catch (Throwable t) {
        LOG.error(() -> "Error handler invocation failed for " + getIdentifier(informationPoint), t);
    }
}
 
Example #25
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object invokeMethod(final String name, final Object... arguments) throws MissingMethodException {
    try {
        return getMetaClass().invokeMethod(bean, name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example #26
Source File: GroovyScriptEngine.java    From james with Apache License 2.0 5 votes vote down vote up
@Override
public void invokeSuccessHandler(InformationPoint informationPoint,
                                 Method origin,
                                 List<RuntimeInformationPointParameter> parameters,
                                 Object instance,
                                 Thread currentThread,
                                 Instant eventTime,
                                 Duration executionTime,
                                 String[] callStack,
                                 Object returnValue,
                                 CompletableFuture<Object> initialContextProvider) {
    LOG.trace(() -> "Invoking success handler for " + getIdentifier(informationPoint));
    try {
        Stopwatch stopwatch = Stopwatch.createStarted();
        InformationPointHandler handler = createOrGetCachedHandler(informationPoint);
        SuccessHandlerContext handlerContext = new SuccessHandlerContext(
                informationPoint.getClassName(), informationPoint.getMethodName(), origin, parameters, instance,
                currentThread, eventTime, executionTime, callStack, returnValue, initialContextProvider.get());
        handler.invokeMethod(SUCCESS_HANDLER_FUNCTION, new Object[]{handlerContext});
        stopwatch.stop();
        LOG.trace(() -> "Success handler invocation took " + stopwatch.elapsed());
    } catch (CompilationFailedException e) {
        LOG.error(() -> "Script compilation failed when calling success handler for " + getIdentifier(informationPoint), e);
    } catch (MissingMethodException mme) {
        LOG.error(() -> "Success handler function missing for " + getIdentifier(informationPoint), mme);
    } catch (Throwable t) {
        LOG.error(() -> "Success handler invocation failed for " + getIdentifier(informationPoint), t);
    }
}
 
Example #27
Source File: GroovyScriptEngine.java    From james with Apache License 2.0 5 votes vote down vote up
@Override
public Object invokePrepareContext(InformationPoint informationPoint,
                                   Method origin,
                                   List<RuntimeInformationPointParameter> parameters,
                                   Object instance,
                                   Thread currentThread,
                                   String contextKey) {
    LOG.trace(() -> "Invoking prepareContext handler for " + getIdentifier(informationPoint));

    try {
        InformationPointHandler handler = createOrGetCachedHandler(informationPoint);
        PrepareContextHandlerContext contextPrepareArgs = new PrepareContextHandlerContext(
                informationPoint.getClassName(),
                informationPoint.getMethodName(),
                origin,
                instance,
                parameters,
                currentThread,
                contextKey);

        final Object result = handler.invokeMethod(PREPARE_CONTEXT, new Object[]{contextPrepareArgs});
        LOG.trace(() -> "Context preparation " + getIdentifier(informationPoint) + " completed!");
        return result;
    } catch (CompilationFailedException e) {
        LOG.error(() -> "Script compilation failed when calling prepareContext handler for " + getIdentifier(informationPoint), e);
    } catch (MissingMethodException mme) {
        LOG.error(() -> "Success handler function missing for " + getIdentifier(informationPoint), mme);
    } catch (Throwable t) {
        LOG.error(() -> "Success handler invocation failed for " + getIdentifier(informationPoint), t);
    }
    return null;

}
 
Example #28
Source File: ActionDslLoaderTest.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
@Test
public void testUnKnownMethodInScript() {
    ActionDb actionDb = new ActionDslLoader(new GroovyCodeSource(getClass().getResource("/actions2.groovy"))).load(network);
    Action someAction = actionDb.getAction("missingMethod");
    exception.expect(MissingMethodException.class);
    someAction.run(network, null);
}
 
Example #29
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
    try {
        return groovyObject.invokeMethod(name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}
 
Example #30
Source File: BeanDynamicObject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Object invokeMethod(String name, Object... arguments) throws MissingMethodException {
    try {
        return groovyObject.invokeMethod(name, arguments);
    } catch (InvokerInvocationException e) {
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        throw e;
    }
}