Example usage for java.lang StackTraceElement equals

List of usage examples for java.lang StackTraceElement equals

Introduction

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

Prototype

public boolean equals(Object obj) 

Source Link

Document

Returns true if the specified object is another StackTraceElement instance representing the same execution point as this instance.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];

    Object ob = "a";
    System.out.println(e.equals(ob));
}

From source file:Main.java

private static Object findLockedMonitor(StackTraceElement stackTraceElement, Object[] lockedMonitors,
        Method getLockedStackFrameMethod)
        throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    for (Object monitorInfo : lockedMonitors) {
        if (stackTraceElement.equals(getLockedStackFrameMethod.invoke(monitorInfo)))
            return monitorInfo;
    }//from w w  w.j  a  va2s  .c o  m
    return null;
}

From source file:com.chaosinmotion.securechat.server.json.ReturnResult.java

/**
 * Generate an error result. This is used to aid in debugging on the
 * client side. This also initializes an array to help diagnose the 
 * problem client-side.//from   w  w  w  . j a v  a  2s .  c  om
 * 
 * Normally this should never be called.
 * 
 * @param exception
 */
public ReturnResult(Throwable th) {
    success = false;
    errorCode = Errors.ERROR_EXCEPTION;
    errorMessage = "Internal exception: " + th.getMessage();

    exception = new ArrayList<String>();
    boolean cflag = false;
    do {
        if (cflag) {
            exception.add("Caused by " + th.getMessage());
        } else {
            cflag = true;
        }

        StackTraceElement[] e = th.getStackTrace();
        int maxlen = e.length;
        th = th.getCause();
        if (th != null) {
            // If there is a cause, we trim the items we show for this
            // exception by removing the tail of the stack trace that
            // is in common. This helps with reading the stack frame.
            StackTraceElement[] n = th.getStackTrace();
            int nlen = n.length;
            while ((maxlen > 0) && (nlen > 0)) {
                StackTraceElement el = e[maxlen - 1];
                StackTraceElement nl = n[nlen - 1];
                if (el.equals(nl)) {
                    --maxlen;
                    --nlen;
                } else {
                    break;
                }
            }

            // Make sure we show at least one item, unless we don't have
            // a stack frame (which can happen sometimes)
            if (maxlen == 0) {
                maxlen++;
                if (maxlen > e.length)
                    maxlen = e.length;
            }
        }

        // Now add the stack frame
        for (int i = 0; i < maxlen; ++i) {
            exception.add("  " + e[i].toString());
        }

    } while (th != null);
}

From source file:org.jboss.dashboard.profiler.ThreadProfile.java

/**
 * Search for two consecutive stack traces in the specified sample interval & stack level.
 *///from   w  w w.j a va2 s.c  o m
protected List<TimeTrace> calculateTimeTraces(int sampleStart, int sampleEnd, int stackLevel) {
    if (stackTraces == null || stackTraces.size() < 2)
        return null;

    // Look for samples
    List<TimeTrace> results = new ArrayList<TimeTrace>();
    int newTraceStart = -1;
    for (int i = sampleStart + 1; i < sampleEnd; i++) {
        StackTrace previous = stackTraces.get(i - 1);
        StackTrace current = stackTraces.get(i);
        StackTraceElement prevEl = previous.get(stackLevel);
        StackTraceElement currEl = current.get(stackLevel);

        // Mark the beginning of a new stack trace.
        if (prevEl != null && prevEl.equals(currEl)) {
            if (newTraceStart == -1) {
                newTraceStart = i - 1;
            }
        }
        // New trace found.
        else if (newTraceStart != -1) {
            TimeTrace newStackTrace = createTimeTrace(newTraceStart, i, stackLevel);
            results.add(newStackTrace);
            newTraceStart = -1;
        }
    }
    // New trace found.
    if (newTraceStart != -1) {
        TimeTrace newStackTrace = createTimeTrace(newTraceStart, sampleEnd, stackLevel);
        results.add(newStackTrace);
    }
    return results;
}

From source file:org.jboss.dashboard.profiler.ThreadProfile.java

/**
 * Create a time trace with samples belonging to the specified interval.
 *///  w w w. ja v a  2 s.  c o m
protected TimeTrace createTimeTrace(int traceStart, int traceEnd, int stackLevel) {
    // Determine the stack length.
    int stackLength = stackLevel + 1;
    boolean stop = false;
    while (!stop) {
        StackTrace first = stackTraces.get(traceStart);
        StackTraceElement firstEl = first.get(stackLength);
        for (int i = traceStart + 1; i < traceEnd && !stop; i++) {
            StackTrace current = stackTraces.get(i);
            StackTraceElement currEl = current.get(stackLength);
            if (firstEl == null || !firstEl.equals(currEl)) {
                stop = true;
            }
        }
        if (!stop) {
            stackLength++;
        }
    }
    // Create the stack trace.
    StackTraceElement[] trace = stackTraces.get(traceStart).from(0, stackLength);
    List<StackTrace> samples = new ArrayList(stackTraces.subList(traceStart, traceEnd));
    List<TimeTrace> children = calculateTimeTraces(traceStart, traceEnd, stackLength);
    return new TimeTrace(trace, samples, children, null);
}