Example usage for java.lang IllegalArgumentException getCause

List of usage examples for java.lang IllegalArgumentException getCause

Introduction

In this page you can find the example usage for java.lang IllegalArgumentException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java

@Test
public void testThrowMessageForMessageOnViolation() throws Exception {
    final ParametersPassesExpression annotation = proxyAnnotation(ParametersPassesExpression.class, "value",
            "myExpression", "messageOnViolation", "My message - ${#expression}");
    final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall(
            ParametersPassesExpressionUnitTest.class, this, "test", "a", 1, "b", 2);
    try {/*from ww w .j  a  va 2 s .  c  o m*/
        new Evaluator().throwMessageFor(annotation, methodCall, null);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("My message - " + annotation.value()));
        assertThat(e.getCause(), nullValue());
    }
    final Throwable cause = new Throwable("myCause");
    try {
        new Evaluator().throwMessageFor(annotation, methodCall, cause);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("My message - " + annotation.value()));
        assertThat(e.getCause(), is(cause));
    }
}

From source file:org.sipfoundry.sipxconfig.setting.BeanValueStorage.java

public SettingValue getSettingValue(Setting setting) {
    String path = setting.getPath();
    Method m = m_methods.get(path);
    if (m == null) {
        return null;
    }//from   w  ww .j  a va  2 s . c  o  m
    try {
        // should be getter (although not strictly nec), with no args
        Object result = m.invoke(m_bean);
        if (result == null) {
            // obstain on null.
            // NOTE: There is not way to return NULL as a setting value. If this
            // is nec., I would suggest adding field to SettingEntry annotation
            // called "obstainOn" and check if that matches this result.
            return null;
        }

        String svalue = setting.getType().convertToStringValue(result);
        return new SettingValueImpl(svalue);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof NoValueException) {
            // this is OK - it means bean does not have any value to provide
            return null;
        }
        // unwrap RuntimeExceptions
        if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        }
        throw new RuntimeException(cause);
    }
}

From source file:edu.vt.middleware.ldap.cli.AbstractCli.java

/**
 * Parses command line options and dispatches to the requested action, or the
 * default action if no action is specified.
 *
 * @param  args  command line arguments/*from w  ww . j  av a  2  s  .co  m*/
 */
public final void performAction(final String[] args) {
    initOptions();
    try {
        if (args.length > 0) {
            final CommandLineParser parser = new GnuParser();
            final CommandLine line = parser.parse(options, args, false);
            dispatch(line);
        } else {
            printExamples();
        }
    } catch (ParseException pex) {
        System.err.println("Failed parsing command arguments: " + pex.getMessage());
    } catch (IllegalArgumentException iaex) {
        String msg = "Operation failed: " + iaex.getMessage();
        if (iaex.getCause() != null) {
            msg += " Underlying reason: " + iaex.getCause().getMessage();
        }
        System.err.println(msg);
    } catch (RuntimeException rex) {
        throw rex;
    } catch (Exception ex) {
        System.err.println("Operation failed:");
        ex.printStackTrace(System.err);
    }
}

From source file:org.echocat.redprecursor.annotations.ParametersPassesExpressionUnitTest.java

@Test
public void testThrowMessageForEmptyMessageOnViolation() throws Exception {
    final ParametersPassesExpression annotation = proxyAnnotation(ParametersPassesExpression.class, "value",
            "myExpression", "messageOnViolation", "");
    final MethodCall<ParametersPassesExpressionUnitTest> methodCall = toMethodCall(
            ParametersPassesExpressionUnitTest.class, this, "test", "a", 1, "b", 2);
    try {//from w  w w. ja  v  a2  s  . co m
        new Evaluator().throwMessageFor(annotation, methodCall, null);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("Expression not passed: " + annotation.value()));
        assertThat(e.getCause(), nullValue());
    }
    final Throwable cause = new Throwable("myCause");
    try {
        new Evaluator().throwMessageFor(annotation, methodCall, cause);
        fail("Exception missing");
    } catch (IllegalArgumentException e) {
        assertThat(e.getMessage(), is("Expression not passed: " + annotation.value()));
        assertThat(e.getCause(), is(cause));
    }
}

From source file:edu.vt.middleware.ldap.AbstractCli.java

/**
 * Parses command line options and invokes the proper handler to perform the
 * requested action, or the default action if no action is specified.
 *
 * @param  args  Command line arguments.
 */// w w w  .j a va  2 s . c  o  m
public final void performAction(final String[] args) {
    initOptions();
    try {
        if (args.length > 0) {
            final CommandLineParser parser = new GnuParser();
            final CommandLine line = parser.parse(options, args);
            dispatch(line);
        } else {
            printExamples();
        }
    } catch (ParseException pex) {
        System.err.println("Failed parsing command arguments: " + pex.getMessage());
    } catch (IllegalArgumentException iaex) {
        String msg = "Operation failed: " + iaex.getMessage();
        if (iaex.getCause() != null) {
            msg += " Underlying reason: " + iaex.getCause().getMessage();
        }
        System.err.println(msg);
    } catch (Exception ex) {
        System.err.println("Operation failed:");
        ex.printStackTrace(System.err);
    }
}

From source file:org.tango.server.device.AroundInvokeImpl.java

/**
 * Call aroundInvoke implementation/*from   w  w  w  . j a v  a  2  s  .  c om*/
 *
 * @param ctx
 *            invocation context
 * @throws DevFailed
 */
public void aroundInvoke(final InvocationContext ctx) throws DevFailed {
    xlogger.entry();
    if (aroundInvokeMethod != null) {
        try {
            aroundInvokeMethod.invoke(businessObject, ctx);
        } catch (final IllegalArgumentException e) {
            DevFailedUtils.throwDevFailed(e);
        } catch (final IllegalAccessException e) {
            DevFailedUtils.throwDevFailed(e);
        } catch (final InvocationTargetException e) {
            if (e.getCause() instanceof DevFailed) {
                throw (DevFailed) e.getCause();
            } else {
                DevFailedUtils.throwDevFailed(e.getCause());
            }
        }
    }
    xlogger.exit();
}

From source file:org.tango.server.command.ReflectCommandBehavior.java

@Override
public Object execute(final Object arg) throws DevFailed {
    xlogger.entry();/*  ww w  .  j  a v  a2  s.c o m*/
    Object obj = null;
    try {
        if (!config.getInType().equals(Void.class)) {
            checkInputType(arg);
            // execute with params
            obj = executeMethod.invoke(businessObject, arg);
        } else {
            // execute without params
            obj = executeMethod.invoke(businessObject);
        }
    } catch (final IllegalArgumentException e) {
        DevFailedUtils.throwDevFailed(e);
    } catch (final IllegalAccessException e) {
        DevFailedUtils.throwDevFailed(e);
    } catch (final InvocationTargetException e) {
        if (e.getCause() instanceof DevFailed) {
            throw (DevFailed) e.getCause();
        } else {
            DevFailedUtils.throwDevFailed(e.getCause());
        }
    }

    xlogger.exit();
    return obj;
}

From source file:org.ldaptive.cli.AbstractCli.java

/**
 * Parses command line options and dispatches to the requested action, or the
 * default action if no action is specified.
 *
 * @param  args  command line arguments/*from   w w w.j a v a2s  .c  o  m*/
 *
 * @return  status code
 */
public final int performAction(final String[] args) {
    initOptions();

    int status = -1;
    try {
        if (args.length > 0) {
            final CommandLineParser parser = new GnuParser();
            final CommandLine line = parser.parse(options, args, false);
            status = dispatch(line);
        } else {
            printExamples();
        }
    } catch (ParseException pex) {
        System.err.println("Failed parsing command arguments: " + pex.getMessage());
    } catch (IllegalArgumentException iaex) {
        String msg = "Operation failed: " + iaex.getMessage();
        if (iaex.getCause() != null) {
            msg += " Underlying reason: " + iaex.getCause().getMessage();
        }
        System.err.println(msg);
    } catch (RuntimeException rex) {
        throw rex;
    } catch (LdapException ex) {
        System.err.println("LDAP Operation failed:");
        ex.printStackTrace(System.err);
        if (ex.getResultCode() != null) {
            status = ex.getResultCode().value();
        }
    } catch (Exception ex) {
        System.err.println("Operation failed:");
        ex.printStackTrace(System.err);
    }
    return status;
}

From source file:pl.nask.hsn2.service.urlfollower.Link.java

public Link(String baseUrl, String relativeUrl, boolean enableIISdecode) throws URISyntaxException {
    decodeIIS = enableIISdecode;//from  w w w .  j  ava2s .  c  om
    this.baseUrl = baseUrl;
    URI baseURI = new URI(format(baseUrl));
    if (!decodeIIS && IISEncDec.isIISencoded(relativeUrl)) {
        this.relativeUrl = relativeUrl;
        int i = relativeUrl.indexOf("%u");
        String rel = format(relativeUrl.substring(0, i));
        append = format(relativeUrl.substring(i));
        if (rel.length() == 0) {
            rel = "/";
        }
        absoluteUrl = URIUtils.resolve(baseURI, rel);
        return;
    } else if (decodeIIS && IISEncDec.isIISencoded(relativeUrl)) {
        this.relativeUrl = IISEncDec.convertToUTF8(format(relativeUrl));
    } else {
        this.relativeUrl = relativeUrl;
    }
    append = "";
    try {
        absoluteUrl = URIUtils.resolve(baseURI, format(this.relativeUrl));
    } catch (IllegalArgumentException e) {
        LOGGER.debug("Error while processing URI", e);
        throw new URISyntaxException("Cannot convert to absolute URL: " + relativeUrl,
                e.getCause().getMessage());
    }
}

From source file:org.jboss.arquillian.ajocado.command.CommandContextImpl.java

/**
 * <p>//  w  w w  . j a  v  a  2 s . co m
 * For each remaining interceptor in list call it's intercept method.
 * </p>
 *
 * <p>
 * Watch if the following interceptor call's in it's {@link CommandInterceptor#intercept(CommandContext)} method body method
 * {@link CommandContextImpl#invoke()} at least once. If not, this interceptor will raise
 * {@link CommandInterceptorException}.
 * </p>
 *
 * @return the return value of executing the command on given commandProcessor
 * @throws CommandInterceptorException if the subsequent interceptor doesn't call {@link CommandContextImpl#invoke()} in
 *         it's {@link CommandInterceptor#intercept(CommandContext)} method body.
 */
@Override
public Object invoke() throws CommandInterceptorException {
    invocations += 1;
    final int currentInvocations = invocations;
    if (interceptors.hasNext()) {
        CommandInterceptor interceptor = interceptors.next();
        interceptor.intercept(this);
        if (currentInvocations == invocations) {
            throw new CommandInterceptorException();
        }
        return result;
    } else {
        try {
            result = method.invoke(commandProcessor, new Object[] { command, args });
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e.getMessage(), e);
        } catch (InvocationTargetException e) {
            if (e.getCause() instanceof RuntimeException) {
                throw (RuntimeException) e.getCause();
            } else {
                throw new RuntimeException(e.getCause());
            }
        }
        return result;
    }
}