Example usage for java.lang RuntimeException setStackTrace

List of usage examples for java.lang RuntimeException setStackTrace

Introduction

In this page you can find the example usage for java.lang RuntimeException setStackTrace.

Prototype

public void setStackTrace(StackTraceElement[] stackTrace) 

Source Link

Document

Sets the stack trace elements that will be returned by #getStackTrace() and printed by #printStackTrace() and related methods.

Usage

From source file:org.dphibernate.adapters.RemotingAdapter.java

/**
 * Invokes the dpHibernate serializer to replace entities with lazy-loading
 * equvilants//www .  j ava 2s .  c  o m
 * 
 * @param results
 * @return
 */
private Object serializeResults(Object results) {
    try {
        StopWatch sw = new StopWatch("serialize");

        ISerializer serializer = serializerFactory.createSerializerFor(results).build();
        results = serializer.serialize();

        sw.stopAndLog();
    } catch (Exception ex) {
        ex.printStackTrace();
        // throw error back to flex
        // todo: replace with custom exception
        RuntimeException re = new RuntimeException(ex.getMessage());
        re.setStackTrace(ex.getStackTrace());
        throw re;
    }
    return results;
}

From source file:org.eclipse.recommenders.stacktraces.rcp.actions.LogErrorsAction.java

private void logMultiStatusDelayed() {
    int counter = 0;
    IStatus[] children = new IStatus[3];
    for (int i = 0; i < children.length; i++) {
        RuntimeException cause = new IllegalArgumentException("cause" + i);
        cause.setStackTrace(createTrace(3));
        Exception exception = new RuntimeException("exception message", cause);
        exception.setStackTrace(createTrace(3));
        children[i] = new Status(IStatus.ERROR, "org.eclipse.recommenders.stacktraces.rcp",
                "status error message " + ++counter, exception);
    }/*from w  w  w.j a va  2  s.com*/
    try {
        Thread.sleep(750);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    log.log(new MultiStatus("org.eclipse.recommenders.stacktraces.rcp", IStatus.ERROR, children,
            "status error message", new RuntimeException()));
}

From source file:org.eclipse.recommenders.stacktraces.rcp.actions.LogErrorsAction.java

private void logManyDifferentErrors() {
    for (int k = 0; k < 10; k++) {
        RuntimeException ex = new IllegalArgumentException("cause" + k);
        StackTraceElement[] trace = createTrace(k);
        ex.setStackTrace(trace);
        log.log(new Status(IStatus.ERROR, "org.eclipse.recommenders.stacktraces.rcp", "error", ex));
    }//from  ww  w .ja  va  2s.c  o  m
}

From source file:org.eclipse.recommenders.stacktraces.rcp.actions.LogErrorsAction.java

private void logStressTest() {
    ExecutorService pool = Executors.newFixedThreadPool(200);
    final Random random = new Random();
    for (int i = 0; i < 100000; i++) {
        pool.execute(new Runnable() {

            @Override//from www.j  av  a  2s . c o m
            public void run() {
                RuntimeException ex = new IllegalArgumentException("cause");
                StackTraceElement[] trace = createRandomTrace();
                ex.setStackTrace(trace);
                final Status status = new Status(IStatus.ERROR, "org.eclipse.recommenders.stacktraces.rcp",
                        "error", ex);
                if (random.nextBoolean()) {
                    log.log(status);
                } else {
                    if (random.nextBoolean()) {
                        Display.getDefault().syncExec(new ExecuteLog(status));
                    } else {
                        Display.getDefault().asyncExec(new ExecuteLog(status));
                    }
                }
            }
        });
    }
}

From source file:org.everit.osgi.dev.lqmg.LQMGMain.java

/**
 * The command line processor.//from  www. j  av  a 2s . c  om
 *
 * @param args
 *            the arguments.
 */
public static void main(final String[] args) {
    Options options = new Options();
    options.addOption("b", ARG_BUNDLES, true, "Location to the bundles separated by semicolon");
    options.addOption("p", ARG_PACKAGES, true, "Package names separated by comma that should be generated."
            + " If not defined, all packages will be generated.");
    options.addOption("cp", ARG_CAPABILITY, true,
            "Expression that is used to select the first schema based on the"
                    + " capabilities that are provided by the bundles.");
    options.addOption("o", ARG_OUTPUT_FOLDER, true,
            "Path of the folder where the classes should be" + " generated");
    options.addOption("c", ARG_LQMG_CONFIG_XML, true, "Path of an optional configuration XML that can override"
            + " configurations coming from the capabilities");
    options.addOption("h", ARG_HACK_WIRES, true,
            "Whether to try redeploy bundles with unsatisfied constraintsin"
                    + " the way that their requirements are changed to be optional. Default: true");
    options.addOption("h", ARG_INNER_CLASSES_FOR_KEYS, true,
            "Whether to generate inner classes for constraints. Default: true");
    options.addOption("ds", ARG_DEFAULT_SCHEMA, true,
            "Default schema where tables will be generated. This schema will be passed in the constructor of"
                    + " the generated metadata classes where the liquibase changelog file does not contain"
                    + " schema information. It is recommended to define a unique value and use the runtime schema"
                    + " renaming functionality of QueryDSL.");

    CommandLineParser commandLineParser = new BasicParser();
    CommandLine commandLine;
    try {
        commandLine = commandLineParser.parse(options, args, true);
    } catch (ParseException e) {
        LQMGMain.printHelp(options);
        RuntimeException returnE = new RuntimeException(e);
        returnE.setStackTrace(new StackTraceElement[0]);
        throw returnE;
    }

    String outputFolder = LQMGMain.evaluateMandatoryOptionValue(ARG_OUTPUT_FOLDER, commandLine, options);
    String bundles = LQMGMain.evaluateMandatoryOptionValue(ARG_BUNDLES, commandLine, options);
    String changelog = LQMGMain.evaluateMandatoryOptionValue(ARG_CAPABILITY, commandLine, options);
    String packages = commandLine.getOptionValue(ARG_PACKAGES);
    String configurationXMLPath = commandLine.getOptionValue(ARG_LQMG_CONFIG_XML);
    String hackWires = commandLine.getOptionValue(ARG_HACK_WIRES);
    String innerClassesForKeys = commandLine.getOptionValue(ARG_INNER_CLASSES_FOR_KEYS);
    String defaultSchema = commandLine.getOptionValue(ARG_DEFAULT_SCHEMA);

    GenerationProperties generationProps = new GenerationProperties(changelog, bundles.split("\\;"),
            outputFolder);

    generationProps.setConfigurationPath(configurationXMLPath);
    generationProps.setDefaultSchema(defaultSchema);

    if (packages != null) {
        generationProps.setPackages(packages.split("\\,"));
    }

    if (hackWires != null) {
        generationProps.setHackWires(Boolean.valueOf(hackWires));
    }

    if (innerClassesForKeys != null) {
        generationProps.setHackWires(Boolean.valueOf(innerClassesForKeys));
    }

    LQMG.generate(generationProps);
}

From source file:org.everit.persistence.lqmg.LQMGMain.java

/**
 * The command line processor./*from  w  ww  .j  av  a  2s.  co  m*/
 *
 * @param args
 *          the arguments.
 */
public static void main(final String[] args) {
    Options options = new Options();
    options.addOption("b", ARG_BUNDLES, true, "Location to the bundles separated by semicolon");
    options.addOption("p", ARG_PACKAGES, true, "Package names separated by comma that should be generated."
            + " If not defined, all packages will be generated.");
    options.addOption("cp", ARG_CAPABILITY, true,
            "Expression that is used to select the first capability based on the"
                    + " capabilities that are provided by the bundles.");
    options.addOption("o", ARG_OUTPUT_FOLDER, true,
            "Path of the folder where the classes should be" + " generated");
    options.addOption("c", ARG_LQMG_CONFIG_XML, true, "Path of an optional configuration XML that can override"
            + " configurations coming from the capabilities");
    options.addOption("h", ARG_HACK_WIRES, true,
            "Whether to try redeploy bundles with unsatisfied constraintsin"
                    + " the way that their requirements are changed to be optional. Default: true");
    options.addOption("h", ARG_INNER_CLASSES_FOR_KEYS, true,
            "Whether to generate inner classes for constraints. Default: true");
    options.addOption("ds", ARG_DEFAULT_SCHEMA, true,
            "Default schema where tables will be generated. This schema will be passed in the "
                    + "constructor of the generated metadata classes where the liquibase changelog file "
                    + "does not contain schema information. It is recommended to define a unique value "
                    + "and use the runtime schema renaming functionality of QueryDSL.");

    CommandLineParser commandLineParser = new BasicParser();
    CommandLine commandLine;
    try {
        commandLine = commandLineParser.parse(options, args, true);
    } catch (ParseException e) {
        LQMGMain.printHelp(options);
        RuntimeException returnE = new RuntimeException(e);
        returnE.setStackTrace(new StackTraceElement[0]);
        throw returnE;
    }

    String outputFolder = LQMGMain.evaluateMandatoryOptionValue(ARG_OUTPUT_FOLDER, commandLine, options);
    String bundles = LQMGMain.evaluateMandatoryOptionValue(ARG_BUNDLES, commandLine, options);
    String changelog = LQMGMain.evaluateMandatoryOptionValue(ARG_CAPABILITY, commandLine, options);
    String packages = commandLine.getOptionValue(ARG_PACKAGES);
    String configurationXMLPath = commandLine.getOptionValue(ARG_LQMG_CONFIG_XML);
    String hackWires = commandLine.getOptionValue(ARG_HACK_WIRES);
    String innerClassesForKeys = commandLine.getOptionValue(ARG_INNER_CLASSES_FOR_KEYS);
    String defaultSchema = commandLine.getOptionValue(ARG_DEFAULT_SCHEMA);

    GenerationProperties generationProps = new GenerationProperties(changelog, bundles.split("\\;"),
            outputFolder);

    generationProps.setConfigurationPath(configurationXMLPath);
    generationProps.setDefaultSchema(defaultSchema);

    if (packages != null) {
        generationProps.setPackages(packages.split("\\,"));
    }

    if (hackWires != null) {
        generationProps.setHackWires(Boolean.valueOf(hackWires));
    }

    if (innerClassesForKeys != null) {
        generationProps.setHackWires(Boolean.valueOf(innerClassesForKeys));
    }

    LQMG.generate(generationProps);
}

From source file:org.openspotlight.graph.query.XPathStatementBuilder.java

/**
 * Validate.//from w ww .  ja va 2s .  c  om
 * 
 * @param statement the statement
 */
private void validate(final Statement statement) {
    if (statement != null) {
        for (final Condition condition : statement.conditions) {
            if (!condition.closed) {
                final RuntimeException e = new SLRuntimeException("All conditions must be closed.");
                e.setStackTrace(condition.stackTrace);
                throw e;
            }
            validate(condition.innerStatement);
        }
    }
}

From source file:org.sonar.core.persistence.AbstractDaoTestCase.java

private static RuntimeException translateException(String msg, Exception cause) {
    RuntimeException runtimeException = new RuntimeException(
            String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
    runtimeException.setStackTrace(cause.getStackTrace());
    return runtimeException;
}

From source file:org.sonar.db.AbstractDbTester.java

public static RuntimeException translateException(String msg, Exception cause) {
    RuntimeException runtimeException = new RuntimeException(
            String.format("%s: [%s] %s", msg, cause.getClass().getName(), cause.getMessage()));
    runtimeException.setStackTrace(cause.getStackTrace());
    return runtimeException;
}