Example usage for java.lang StackTraceElement toString

List of usage examples for java.lang StackTraceElement toString

Introduction

In this page you can find the example usage for java.lang StackTraceElement toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of this stack trace element.

Usage

From source file:com.zinnia.nectar.regression.hadoop.primitive.jobs.SigmaXYJob.java

public Double call() throws NectarException {
    double value = 0;
    JobControl jobControl = new JobControl("sigmajob");
    try {/*from  w  w  w  .ja v a2  s .  c  om*/
        job = new Job();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    job.setJarByClass(SigmaXYJob.class);
    log.info("SigmaXY Job initialized");
    log.warn("SigmaXY job: Processing...Do not terminate/close");
    log.debug("SigmaXY job: Mapping process started");

    try {
        ChainMapper.addMapper(job, FieldSeperator.FieldSeperationMapper.class, LongWritable.class, Text.class,
                NullWritable.class, Text.class, job.getConfiguration());
        ChainMapper.addMapper(job, SigmaXYMapper.class, NullWritable.class, Text.class, Text.class,
                DoubleWritable.class, job.getConfiguration());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    job.getConfiguration().set("fields.spec", x + "," + y);

    job.setReducerClass(DoubleSumReducer.class);
    try {
        FileInputFormat.addInputPath(job, new Path(inputFilePath));
        fs = FileSystem.get(job.getConfiguration());
        if (!fs.exists(new Path(inputFilePath))) {
            throw new NectarException("Exception occured:File " + inputFilePath + " not found ");
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        String trace = new String();
        log.error(e.toString());
        for (StackTraceElement s : e.getStackTrace()) {
            trace += "\n\t at " + s.toString();
        }
        log.debug(trace);
        log.debug("SigmaXY Job terminated abruptly\n");
        throw new NectarException();
    }
    FileOutputFormat.setOutputPath(job, new Path(outputFilePath));
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(DoubleWritable.class);
    job.setInputFormatClass(TextInputFormat.class);
    log.debug("SigmaXY job: Mapping process completed");

    log.debug("SigmaXY job: Reducing process started");
    try {
        controlledJob = new ControlledJob(job.getConfiguration());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    jobControl.addJob(controlledJob);
    Thread thread = new Thread(jobControl);
    thread.start();
    while (!jobControl.allFinished()) {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    jobControl.stop();
    FileSystem fs;
    try {
        fs = FileSystem.get(job.getConfiguration());
        FSDataInputStream in = fs.open(new Path(outputFilePath + "/part-r-00000"));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
        String valueLine = bufferedReader.readLine();
        String[] fields = valueLine.split("\t");
        value = Double.parseDouble(fields[1]);
        bufferedReader.close();
        in.close();
    } catch (IOException e) {
        log.error("Exception occured: Output file cannot be read.");
        log.debug(e.getMessage());
        log.debug("SigmaXY Job terminated abruptly\n");
        throw new NectarException();
    }
    log.debug("SigmaXY job: Reducing process completed");
    log.info("SigmaXY Job completed\n");
    return value;
}

From source file:hudson.Functions.java

@IgnoreJRERequirement
public static String dumpThreadInfo(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder(
            "\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " " + ti.getThreadState());
    if (ti.getLockName() != null) {
        sb.append(" on " + ti.getLockName());
    }/*from  w w w. ja va2s. c  o m*/
    if (ti.getLockOwnerName() != null) {
        sb.append(" owned by \"" + ti.getLockOwnerName() + "\" Id=" + ti.getLockOwnerId());
    }
    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    StackTraceElement[] stackTrace = ti.getStackTrace();
    for (int i = 0; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && ti.getLockInfo() != null) {
            Thread.State ts = ti.getThreadState();
            switch (ts) {
            case BLOCKED:
                sb.append("\t-  blocked on " + ti.getLockInfo());
                sb.append('\n');
                break;
            case WAITING:
                sb.append("\t-  waiting on " + ti.getLockInfo());
                sb.append('\n');
                break;
            case TIMED_WAITING:
                sb.append("\t-  waiting on " + ti.getLockInfo());
                sb.append('\n');
                break;
            default:
            }
        }

        for (MonitorInfo mi : ti.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }

    LockInfo[] locks = ti.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}

From source file:com.google.api.ads.adwords.jaxws.extensions.kratu.restserver.AbstractServerResource.java

protected String stackTraceToString(Throwable e) {
    StringBuilder sb = new StringBuilder();
    for (StackTraceElement element : e.getStackTrace()) {
        sb.append(element.toString());
        sb.append("\n");
    }/*from w w w.j a  v a2  s. c o  m*/
    return sb.toString();
}

From source file:org.spout.vanilla.plugin.protocol.PasteExceptionHandler.java

private void logTrace(StringBuilder builder, Exception e) {
    Throwable parent = e;//from  w  ww .  j a v  a2  s  .c  om
    String indent = "    ";
    while (parent != null) {
        if (parent == e) {
            builder.append(indent).append("Trace:").append("\n");
        } else {
            builder.append(indent).append("Caused By: (").append(parent.getClass().getSimpleName()).append(")")
                    .append("\n");
            builder.append(indent).append("    ").append("[").append(parent.getMessage()).append("]")
                    .append("\n");
        }
        for (StackTraceElement ele : e.getStackTrace()) {
            builder.append(indent).append("    ").append(ele.toString()).append("\n");
        }
        indent += "    ";
        parent = parent.getCause();
    }
}

From source file:com.codebutler.farebot.activities.AdvancedCardInfoActivity.java

private void reportError() {
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override/*from w  ww.  j  a v a  2s.co m*/
        public void onClick(DialogInterface dialog, int which) {
            StringBuilder builder = new StringBuilder();
            builder.append(Utils.getDeviceInfoString());
            builder.append("\n\n");

            builder.append(mError.toString());
            builder.append("\n");
            builder.append(Utils.getErrorMessage(mError));
            builder.append("\n");
            for (StackTraceElement elem : mError.getStackTrace()) {
                builder.append(elem.toString());
                builder.append("\n");
            }

            builder.append("\n\n");

            try {
                builder.append(Utils.xmlNodeToString(mCard.toXML().getOwnerDocument()));
            } catch (Exception ex) {
                builder.append("Failed to generate XML: ");
                builder.append(ex);
            }

            builder.append("\n\n");
            builder.append(getString(R.string.comments));
            builder.append(":\n\n");

            Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:eric+farebot@codebutler.com"));
            intent.putExtra(Intent.EXTRA_SUBJECT, "FareBot Bug Report");
            intent.putExtra(Intent.EXTRA_TEXT, builder.toString());
            startActivity(intent);

        }
    };
    new AlertDialog.Builder(this).setTitle(R.string.report_error_privacy_title)
            .setMessage(R.string.report_error_privacy_message).setPositiveButton(android.R.string.ok, listener)
            .setNegativeButton(android.R.string.cancel, null).show();
}

From source file:com.zinnia.nectar.regression.hadoop.primitive.jobs.SortJob.java

public Double[] call() throws NectarException {
    // TODO Auto-generated method stub
    JobControl jobControl = new JobControl("Sortjob");
    try {//from  w w  w  .j a v a 2  s. c o m
        job = new Job();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    job.setJarByClass(SortJob.class);
    log.info("Sorting Job initialized");
    log.warn("Sorting job: Processing...Do not terminate/close");
    log.debug("Sorting job: Mapping process started");

    try {
        ChainMapper.addMapper(job, FieldSeperator.FieldSeperationMapper.class, LongWritable.class, Text.class,
                NullWritable.class, Text.class, job.getConfiguration());
        ChainMapper.addMapper(job, SortMapper.class, NullWritable.class, Text.class, DoubleWritable.class,
                DoubleWritable.class, job.getConfiguration());
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    job.getConfiguration().set("fields.spec", "" + column);
    job.setReducerClass(Reducer.class);

    try {
        FileInputFormat.addInputPath(job, new Path(inputFilePath));
        fs = FileSystem.get(job.getConfiguration());
        if (!fs.exists(new Path(inputFilePath))) {
            throw new NectarException("Exception occured:File " + inputFilePath + " not found ");
        }
    } catch (Exception e2) {
        // TODO Auto-generated catch block
        String trace = new String();
        log.error(e2.toString());
        for (StackTraceElement s : e2.getStackTrace()) {
            trace += "\n\t at " + s.toString();
        }
        log.debug(trace);
        log.debug("Sorting Job terminated abruptly\n");
        throw new NectarException();
    }
    FileOutputFormat.setOutputPath(job, new Path(outputFilePath));
    job.setMapOutputValueClass(DoubleWritable.class);
    job.setMapOutputKeyClass(DoubleWritable.class);
    job.setInputFormatClass(TextInputFormat.class);
    log.debug("Sorting job: Mapping process completed");

    log.debug("Sorting job: Reducing process started");
    try {
        controlledJob = new ControlledJob(job.getConfiguration());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    jobControl.addJob(controlledJob);
    Thread thread = new Thread(jobControl);
    thread.start();
    while (!jobControl.allFinished()) {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        FSDataInputStream in = fs.open(new Path(outputFilePath + "/part-r-00000"));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
        String valueLine;
        while ((valueLine = bufferedReader.readLine()) != null) {
            String[] fields = valueLine.split("\t");
            value.add(Double.parseDouble(fields[1]));
        }
        bufferedReader.close();
        in.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        log.error("Exception occured: Output file cannot be read.");
        log.debug(e.getMessage());
        log.debug("Sorting Job terminated abruptly\n");
        throw new NectarException();
    }
    log.debug("Sorting job: Reducing process completed");
    log.info("Sorting Job completed\n");
    return value.toArray(new Double[value.size()]);
}

From source file:net.krautchan.data.KCThread.java

public void recalc() {
    try {//from w w w .  j  a  va2 s. c o m
        Iterator<Entry<Long, KCPosting>> iter = postings.entrySet().iterator();
        if (iter.hasNext()) {
            Entry<Long, KCPosting> entry = iter.next();
            KCPosting posting = entry.getValue();
            if (null == digest) {
                makeDigest(posting);
            }
            if (null == firstPostDate) {
                firstPostDate = posting.getCreated();
            }
        }
        Assert.assertNotNull(this.getDbId());
    } catch (Exception e) {
        String trace = "Exception in KCThread " + kcNummer + " " + e.getClass().getCanonicalName() + "\n";
        for (StackTraceElement elem : e.getStackTrace()) {
            trace += " " + elem.toString() + "\n";
        }
        System.err.println(trace);
    }
}

From source file:net.sourceforge.atunes.ErrorReport.java

/**
 * Returns string information about throwable
 * //  w w  w .  ja  v a 2s  .  c om
 * @return
 */
private String getThrowableString() {
    List<String> values = new ArrayList<String>();
    values.add(StringUtils.getString(this.throwable.getClass().getCanonicalName(), ": ",
            this.throwable.getMessage()));
    for (StackTraceElement ste : this.throwable.getStackTrace()) {
        values.add(StringUtils.getString(ste.toString()));
    }
    Throwable cause = this.throwable.getCause();
    if (cause != null && cause.getStackTrace() != null) {
        values.add("Cause: ");
        for (StackTraceElement ste : cause.getStackTrace()) {
            values.add(StringUtils.getString(ste.toString()));
        }

    }
    return org.apache.commons.lang.StringUtils.join(values, "\n");
}

From source file:com.bluexml.side.clazz.alfresco.reverse.ant.AntReverseTask.java

@Override
public void execute() throws BuildException {

    Collection<File> alfrescoModels = new ArrayList<File>();
    List<IFile> sideModels = new ArrayList<IFile>();
    // get files//from  ww  w .j  a va2s.c  o m
    int msgErr = Project.MSG_ERR;
    for (int i = 0; i < rcs.size(); i++) {
        ResourceCollection rc = (ResourceCollection) rcs.elementAt(i);

        // Step (1) - beware of the ZipFileSet
        if (rc instanceof FileSet && rc.isFilesystemOnly()) {
            FileSet fs = (FileSet) rc;
            DirectoryScanner ds = null;
            try {
                ds = fs.getDirectoryScanner(getProject());
            } catch (BuildException e) {
                if (failonerror || !getMessage(e).endsWith(" not found.")) {
                    throw e;
                } else {
                    log("Warning: " + getMessage(e), msgErr);
                    continue;
                }
            }
            File fromDir = fs.getDir(getProject());
            if (verbose)
                log("FROMDir :" + fromDir);

            String[] srcFiles = ds.getIncludedFiles();
            if (verbose)
                log("srcFiles :");

            for (String string : srcFiles) {

                String fullpath = fromDir + File.separator + string;
                if (verbose)
                    log("* " + fullpath);
                File file = new File(fullpath);
                if (file.exists()) {
                    if (FilenameUtils.getExtension(file.getName()).toLowerCase().equals("xml")) {
                        alfrescoModels.add(file);
                    } else if (FilenameUtils.getExtension(file.getName()).toLowerCase().equals("dt")) {
                        sideModels.add(IFileHelper.getIFile(file));
                    }
                }

            }
            String[] srcDirs = ds.getIncludedDirectories();
            if (verbose)
                log("srcDirs");
            for (String string : srcDirs) {
                if (verbose)
                    log("* " + string);
            }
        }
    }

    try {
        Reverser.executeReverse(alfrescoModels, output, sideModels, verbose);
    } catch (Exception e) {
        log(e, msgErr);
        StackTraceElement[] stackTrace = e.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            log(stackTraceElement.toString(), msgErr);
        }
        if (failonerror) {
            throw new BuildException(e);
        }
    }
    log("execute end");
}

From source file:com.boundlessgeo.geoserver.api.controllers.IO.java

/** Encode an exception */
public static JSONObj error(JSONObj json, Throwable error) {
    if (error != null) {
        String message = null;//from w  w  w . j  av a 2 s. com
        JSONArr cause = new JSONArr();
        for (Throwable t : Throwables.getCausalChain(error)) {
            if (message == null && t.getMessage() != null) {
                message = t.getMessage();
            }
            StringBuilder trace = new StringBuilder();
            for (StackTraceElement e : t.getStackTrace()) {
                trace.append(e.toString()).append('\n');
            }
            cause.addObject().put("exception", t.getClass().getSimpleName()).put("message", t.getMessage())
                    .put("trace", trace.toString());
        }
        if (message == null) {
            message = error.getClass().getSimpleName();
        }
        json.put("message", message != null ? message : error.toString()).put("cause", cause).put("trace",
                Throwables.getStackTraceAsString(error));
    }
    return json;
}