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:com.tc.stats.DSO.java

private static Exception newPlainException(Exception e) {
    String type = e.getClass().getName();
    if (type.startsWith("java.") || type.startsWith("javax.")) {
        return e;
    } else {// w  ww.j a  v  a  2s  .c  o  m
        RuntimeException result = new RuntimeException(e.getMessage());
        result.setStackTrace(e.getStackTrace());
        return result;
    }
}

From source file:com.qmetry.qaf.automation.step.StringTestStep.java

@Override
public Object execute() {
    if (DryRunAnalyzer.isDryRun(this)) {
        return null;
    }/*from   w ww.  ja v a 2  s  .c om*/
    initStep();

    if (null != step) {
        Object retVal = null;
        try {
            retVal = step.execute();
            if (isNotBlank(resultParameterName)) {
                if (resultParameterName.indexOf("${") == 0) {
                    getBundle().setProperty(resultParameterName, retVal);

                } else {
                    getBundle().setProperty("${" + resultParameterName + "}", retVal);

                }

            }
        } catch (Error ae) {
            StepInvocationException se = new StepInvocationException(this, ae);
            ae.setStackTrace(se.getStackTrace());
            throw ae;
        } catch (Throwable e) {
            StepInvocationException se = new StepInvocationException(this, e);
            RuntimeException re = (RuntimeException.class.isAssignableFrom(e.getClass()) ? (RuntimeException) e
                    : new RuntimeException(e));
            re.setStackTrace(se.getStackTrace());
            throw re;
        }
        return retVal;
    }

    throw new StepNotFoundException(this);
}

From source file:net.doubledoordev.fsw.ForgeSubWhitelist.java

private void syncConfig() {
    String[] old = null;//  w w  w . j  ava 2 s  .c  om
    if (configuration.hasKey(MODID, "apiToken")) {
        logger.info("Converting old config to new format.");
        old = new String[] { new Streamer(configuration.get(MODID, "apiToken", "").getString(),
                configuration.get(MODID, "twitch", false).getBoolean(),
                configuration.get(MODID, "beam", false).getBoolean(),
                configuration.get(MODID, "gamewisp", -1).getInt()).toString() };
        configuration.removeCategory(configuration.getCategory(MODID));
    }
    configuration.addCustomCategoryComment(MODID, "This information is required for server side operation.");

    Property p = configuration.get(MODID, "tokens", new String[0],
            "This new format allows you to have a server run by multiple people. Being subscribed to one of them is enough to get on.\n"
                    + "Syntax: (remove quotes, 1 per line)\n" + "    '<apitoken> <twitch> <beam> <gamewisp>'\n"
                    + "Services:\n"
                    + "    <apitoken> is token you get from http://doubledoordev.net/?p=linking\n"
                    + "    <twitch> is true or false. True means let subs from twitch on.\n"
                    + "    <beam> is true or false. True means let subs from beam on.\n"
                    + "    <gamewisp> is a number. -1 means ignore gamewisp subs. Any other number is used as the mimimum gamewisp tear for this server.\n"
                    + "Examples:\n"
                    + "    'TOKEN true false 1'   to allow twitch and tear 1 and above on gamewisp, but ignore beam.\n"
                    + "    'TOKEN true false -1'  to only allow twitch.");
    if (old != null)
        p.set(old);
    String[] lines = p.getStringList();
    streamers = new Streamer[lines.length];
    for (int i = 0; i < lines.length; i++) {
        String[] split = lines[i].split("\\s+");
        String token = split[0];
        if (split.length > 4)
            throw new RuntimeException("Too many parts in the config string: " + lines[i]);
        boolean twitch = split.length > 1 && Boolean.parseBoolean(split[1]);
        boolean beam = split.length > 2 && Boolean.parseBoolean(split[2]);
        int gamewisp = split.length > 3 ? Integer.parseInt(split[3]) : -1;
        streamers[i] = new Streamer(token, twitch, beam, gamewisp);
    }

    kickMsg = configuration.getStringList("kickMsg", MODID, kickMsg,
            "Please put a nice message here. Newline allowed. Its recommended to link to a document explain the auth process and/or your channel. Remember that you cannot click links, so keep it short.");
    closed = configuration.getBoolean("closed", MODID, closed,
            "Used for not-yet-public state. Enable ingame with /closed <true|false>.");
    closed_msg = configuration.getString("closed_msg", MODID, closed_msg,
            "The message when the server is closed.");

    if (configuration.hasChanged())
        configuration.save();

    logger.info("Trying out the API token. This could take a couple of seconds.");
    try {
        for (Streamer s : streamers) {
            //noinspection ResultOfMethodCallIgnored
            IOUtils.toString(new URL(s.baseUrl));
        }
    } catch (IOException ex) {
        RuntimeException e = new RuntimeException("\n\nYour API token is wrong. Update them in the " + MODID
                + " config.\n\nDO NOT POST THIS LOG ANYWHERE ONLINE WITHOUT REMOVING THE BASE_URL IN THE LINE BELOW!\n",
                ex);
        e.setStackTrace(new StackTraceElement[0]);
        throw e;
    }

    logger.info("Configuration:");
    for (Streamer s : streamers)
        logger.info("Token (redacted): {} Twitch: {} Beam: {} Gamewisp: {}", s.redactedToken, s.twitch, s.beam,
                s.gamewisp);
    if (streamers.length == 0)
        logger.warn(
                "YOU DON NOT HAVE ANY TOKENES CONFIGURED. YOU WILL NOT BE ABLE TO LOG ON WITHOUT WHITELISTING!");
}

From source file:de.tud.inf.db.sparqlytics.olap.Compute.java

/**
 * Extends the given runtime exception with the given query string.
 * //from  ww w.j ava 2 s .  co  m
 * @param ex    the exception to extend
 * @param query the query to add to the exception message
 * @return the extended exception
 */
protected RuntimeException extendRuntimeException(RuntimeException ex, String query) {
    StringBuilder builder = new StringBuilder();
    String message = ex.getMessage();
    if (message != null) {
        builder.append(message).append(System.lineSeparator());
    }
    builder.append(ex.getClass().getSimpleName()).append(" caused by query:").append(System.lineSeparator());
    builder.append(query);
    RuntimeException extended = new RuntimeException(builder.toString(), ex.getCause());
    extended.setStackTrace(ex.getStackTrace());
    return extended;
}

From source file:com.msopentech.odatajclient.engine.communication.ODataClientErrorException.java

/**
 * Constructor./*from ww  w.  j  a  v a2  s .  co m*/
 *
 * @param statusLine request status info.
 * @param error OData error to be wrapped.
 */
public ODataClientErrorException(final StatusLine statusLine, final ODataError error) {
    super((StringUtils.isBlank(error.getCode()) ? StringUtils.EMPTY : "(" + error.getCode() + ") ")
            + error.getMessageValue() + " [" + statusLine.toString() + "]");

    this.statusLine = statusLine;
    this.error = error;

    if (this.error.getInnerErrorType() != null && this.error.getInnerErrorMessage() != null) {
        final RuntimeException cause = new RuntimeException(
                this.error.getInnerErrorType() + ": " + this.error.getInnerErrorMessage());

        if (this.error.getInnerErrorStacktrace() != null) {
            List<String> stLines;
            try {
                stLines = IOUtils.readLines(new StringReader(this.error.getInnerErrorStacktrace()));
            } catch (IOException e) {
                stLines = Collections.<String>emptyList();
            }
            StackTraceElement[] stElements = new StackTraceElement[stLines.size()];
            for (int i = 0; i < stLines.size(); i++) {
                final String stLine = stLines.get(i).substring(stLines.get(i).indexOf("at ") + 3);
                final int lastDotPos = stLine.lastIndexOf('.');
                stElements[i] = new StackTraceElement(stLine.substring(0, lastDotPos),
                        stLine.substring(lastDotPos + 1), null, 0);
            }
            cause.setStackTrace(stElements);
        }

        initCause(cause);
    }
}

From source file:cn.bran.play.JapidTemplateBase.java

@Override
protected void handleException(RuntimeException e) {
    if (Play.mode == Mode.PROD)
        throw e;/*w w w.ja v a  2 s.  c  om*/

    // find the latest japidviews exception
    StackTraceElement[] stackTrace = e.getStackTrace();
    for (StackTraceElement ele : stackTrace) {
        String className = ele.getClassName();
        if (className.startsWith("japidviews")) {
            int lineNumber = ele.getLineNumber();
            // TODO: should really remove the Play reference.  Shall we jump to the file system for the source?
            ApplicationClass applicationClass = Play.classes.getApplicationClass(className);
            if (applicationClass != null) {
                // let's get the line of problem
                String jsrc = applicationClass.javaSource;
                String[] splitSrc = jsrc.split("\n");
                String line = splitSrc[lineNumber - 1];
                // can we have a line marker?
                int lineMarker = line.lastIndexOf("// line ");
                if (lineMarker > 0) {
                    int oriLineNumber = Integer.parseInt(line.substring(lineMarker + 8).trim());
                    StackTraceElement[] newStack = new StackTraceElement[stackTrace.length + 1];
                    newStack[0] = new StackTraceElement(sourceTemplate, "", sourceTemplate, oriLineNumber);
                    System.arraycopy(stackTrace, 0, newStack, 1, stackTrace.length);
                    e.setStackTrace(newStack);

                    File file = new File("app/" + sourceTemplate);
                    //         
                    JapidPlayTemplate jpt = new JapidPlayTemplate();
                    jpt.name = sourceTemplate;
                    try {
                        jpt.source = FileUtils.readFileToString(file);
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                    throw new TemplateExecutionException(jpt, oriLineNumber, e.getMessage(), e);
                }
            }
        }
    }
    throw e;
}

From source file:org.apache.pig.backend.hadoop.executionengine.mapreduceExec.PigCombine.java

public void reduce(Tuple key, Iterator<IndexedTuple> values, OutputCollector<Tuple, IndexedTuple> output,
        Reporter reporter) throws IOException {

    try {//w ww.j a va2  s . c  o m
        if (evalPipe == null) {
            finalout = new CombineDataOutputCollector(output);
            evalPipe = esp.setupPipe(null, finalout);
            //throw new RuntimeException("combine spec: " + evalSpec + " combine pipe: " + esp.toString());

            bags = new DataBag[inputCount];
            for (int i = 0; i < inputCount; i++) {
                bags[i] = BagFactory.getInstance().newDefaultBag();
            }
        }

        if (PigInputFormat.getActiveSplit() == null) {
        } else {
            index = PigInputFormat.getActiveSplit().getIndex();
        }

        Datum groupName = key.getField(0);
        finalout.group = key;
        finalout.index = index;

        Tuple t = new Tuple(1 + inputCount);
        t.setField(0, groupName);
        for (int i = 1; i < 1 + inputCount; i++) {
            bags[i - 1].clear();
            t.setField(i, bags[i - 1]);
        }

        while (values.hasNext()) {
            IndexedTuple it = values.next();
            t.getBagField(it.index + 1).add(it.toTuple());
        }
        for (int i = 0; i < inputCount; i++) { // XXX: shouldn't we only do this if INNER flag is set?
            if (t.getBagField(1 + i).size() == 0)
                return;
        }
        //          throw new RuntimeException("combine input: " + t.toString());
        evalPipe.add(t);
        // evalPipe.add(null); // EOF marker
    } catch (Throwable tr) {
        log.error(tr);
        RuntimeException exp = new RuntimeException(tr.getMessage());
        exp.setStackTrace(tr.getStackTrace());
        throw exp;
    }
}

From source file:org.apache.pig.piggybank.storage.AllLoader.java

/**
 * Reads the partition columns/* ww w .  jav a2s  .c o  m*/
 * 
 * @param location
 * @param job
 * @return
 */
private String[] getPartitionColumns(String location, Job job) {

    if (partitionColumns == null) {
        // read the partition columns from the UDF Context first.
        // if not in the UDF context then read it using the PathPartitioner.

        Properties properties = getUDFContext();

        if (properties == null) {
            properties = new Properties();
        }

        String partitionColumnStr = properties.getProperty(PathPartitionHelper.PARTITION_COLUMNS);

        if (partitionColumnStr == null && !(location == null || job == null)) {
            // if it hasn't been written yet.
            Set<String> partitionColumnSet;

            try {
                partitionColumnSet = pathPartitionerHelper.getPartitionKeys(location, job.getConfiguration());
            } catch (IOException e) {

                RuntimeException rte = new RuntimeException(e);
                rte.setStackTrace(e.getStackTrace());
                throw rte;

            }

            if (partitionColumnSet != null) {

                StringBuilder buff = new StringBuilder();

                int i = 0;
                for (String column : partitionColumnSet) {
                    if (i++ != 0) {
                        buff.append(',');
                    }

                    buff.append(column);
                }

                String buffStr = buff.toString().trim();

                if (buffStr.length() > 0) {

                    properties.setProperty(PathPartitionHelper.PARTITION_COLUMNS, buff.toString());
                }

                partitionColumns = partitionColumnSet.toArray(new String[] {});

            }

        } else {
            // the partition columns has been set already in the UDF Context
            if (partitionColumnStr != null) {
                String split[] = partitionColumnStr.split(",");
                Set<String> partitionColumnSet = new LinkedHashSet<String>();
                if (split.length > 0) {
                    for (String splitItem : split) {
                        partitionColumnSet.add(splitItem);
                    }
                }

                partitionColumns = partitionColumnSet.toArray(new String[] {});
            }

        }

    }

    return partitionColumns;

}

From source file:org.apache.pig.piggybank.storage.HiveColumnarLoader.java

/**
 * Reads the partition columns//from www .  j  av  a 2 s .c  o m
 *
 * @param location
 * @param job
 * @return
 */
private Set<String> getPartitionColumns(String location, Job job) {

    if (partitionColumns == null) {
        // read the partition columns from the UDF Context first.
        // if not in the UDF context then read it using the PathPartitioner.

        Properties properties = getUDFContext();

        if (properties == null)
            properties = new Properties();

        String partitionColumnStr = properties.getProperty(PathPartitionHelper.PARTITION_COLUMNS);

        if (partitionColumnStr == null && !(location == null || job == null)) {
            // if it hasn't been written yet.
            Set<String> partitionColumnSet;

            try {
                partitionColumnSet = pathPartitionerHelper.getPartitionKeys(location, job.getConfiguration());
            } catch (IOException e) {

                RuntimeException rte = new RuntimeException(e);
                rte.setStackTrace(e.getStackTrace());
                throw rte;

            }

            if (partitionColumnSet != null) {

                StringBuilder buff = new StringBuilder();

                int i = 0;
                for (String column : partitionColumnSet) {
                    if (i++ != 0) {
                        buff.append(',');
                    }

                    buff.append(column);
                }

                String buffStr = buff.toString().trim();

                if (buffStr.length() > 0) {

                    properties.setProperty(PathPartitionHelper.PARTITION_COLUMNS, buff.toString());
                }

                partitionColumns = partitionColumnSet;

            }

        } else {
            // the partition columns has been set already in the UDF Context
            if (partitionColumnStr != null) {
                String split[] = partitionColumnStr.split(",");
                partitionColumns = new LinkedHashSet<String>();
                if (split.length > 0) {
                    for (String splitItem : split) {
                        partitionColumns.add(splitItem);
                    }
                }
            }

        }

    }

    return partitionColumns;

}

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

/**
 * Checks the remotingMessage for any dpHibernate entities, and expands them
 * using a deserializer./*from  w w  w.  j  a v a2  s .co  m*/
 * 
 * @param remotingMessage
 */
private void deserializeMessage(RemotingMessage remotingMessage) {
    List inArgs = remotingMessage.getParameters();
    if (inArgs != null && inArgs.size() > 0) {
        try {
            StopWatch sw = new StopWatch("deserialize");

            IDeserializer deserializer = getDeserializer();
            Object o = deserializer.translate(this, (RemotingMessage) remotingMessage.clone(), null, null,
                    inArgs);

            sw.stopAndLog();
        } catch (Exception ex) {
            ex.printStackTrace();
            RuntimeException re = new RuntimeException(ex.getMessage());
            re.setStackTrace(ex.getStackTrace());
            throw re;
        }
    }
}