Example usage for java.lang StackTraceElement getClassName

List of usage examples for java.lang StackTraceElement getClassName

Introduction

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

Prototype

public String getClassName() 

Source Link

Document

Returns the fully qualified name of the class containing the execution point represented by this stack trace element.

Usage

From source file:com.eucalyptus.entities.EntityWrapper.java

public static StackTraceElement getMyStackTraceElement() {
    int i = 0;/*w  ww.  ja v a 2 s  .com*/
    for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) {
        if ((i++ < 2) || ste.getClassName().matches(".*EntityWrapper.*")
                || ste.getClassName().matches(".*TxHandle.*")
                || ste.getMethodName().equals("getEntityWrapper")) {
            continue;
        } else {
            return ste;
        }
    }
    throw new RuntimeException("BUG: Reached bottom of stack trace without finding any relevent frames.");
}

From source file:biz.bokhorst.xprivacy.Util.java

public static void logStack(XHook hook, int priority, boolean cl) {
    StringBuilder trace = new StringBuilder();
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
        trace.append(ste.toString());//from  www.j  a  v a2 s. c  om
        if (cl)
            try {
                Class<?> clazz = Class.forName(ste.getClassName(), false, loader);
                trace.append(" [");
                trace.append(clazz.getClassLoader().toString());
                trace.append("]");
            } catch (ClassNotFoundException ignored) {
            }
        trace.append("\n");
    }
    log(hook, priority, trace.toString());
}

From source file:com.simiacryptus.util.Util.java

/**
 * Report./*w w  w.  j  a va2  s. c  o m*/
 *
 * @param fragments the fragments
 * @throws IOException the io exception
 */
public static void report(@javax.annotation.Nonnull final Stream<String> fragments) throws IOException {
    @javax.annotation.Nonnull
    final File outDir = new File("reports");
    outDir.mkdirs();
    final StackTraceElement caller = com.simiacryptus.util.Util
            .getLast(Arrays.stream(Thread.currentThread().getStackTrace())//
                    .filter(x -> x.getClassName().contains("simiacryptus")));
    @javax.annotation.Nonnull
    final File report = new File(outDir, caller.getClassName() + "_" + caller.getLineNumber() + ".html");
    @javax.annotation.Nonnull
    final PrintStream out = new PrintStream(new FileOutputStream(report));
    out.println("<html><head></head><body>");
    fragments.forEach(out::println);
    out.println("</body></html>");
    out.close();
    Desktop.getDesktop().browse(report.toURI());
}

From source file:rpc.TestRPC.java

/**
 * Count the number of threads that have a stack frame containing the given
 * string//from   w ww  .  jav  a2 s.c  o  m
 */
private static int countThreads(String search) {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

    int count = 0;
    ThreadInfo[] infos = threadBean.getThreadInfo(threadBean.getAllThreadIds(), 20);
    for (ThreadInfo info : infos) {
        if (info == null)
            continue;
        for (StackTraceElement elem : info.getStackTrace()) {
            if (elem.getClassName().contains(search)) {
                count++;
                break;
            }
        }
    }
    return count;
}

From source file:com.egt.core.aplicacion.Bitacora.java

private static String getStackTraceElementTrack(StackTraceElement trace) {
    return trace == null ? ""
            : " @ " + getSimpleClassName(trace.getClassName()) + "." + trace.getMethodName() + ":"
                    + trace.getLineNumber();
}

From source file:cat.ereza.customactivityoncrash.CustomActivityOnCrash.java

/**
 * INTERNAL method that checks if the stack trace that just crashed is conflictive. This is true in the following scenarios:
 * - The application has crashed while initializing (handleBindApplication is in the stack)
 * - The error activity has crashed (activityClass is in the stack)
 *
 * @param throwable     The throwable from which the stack trace will be checked
 * @param activityClass The activity class to launch when the app crashes
 * @return true if this stack trace is conflictive and the activity must not be launched, false otherwise
 */// w  w w . j ava 2 s . co  m
private static boolean isStackTraceLikelyConflictive(Throwable throwable,
        Class<? extends Activity> activityClass) {
    do {
        StackTraceElement[] stackTrace = throwable.getStackTrace();
        for (StackTraceElement element : stackTrace) {
            if ((element.getClassName().equals("android.app.ActivityThread")
                    && element.getMethodName().equals("handleBindApplication"))
                    || element.getClassName().equals(activityClass.getName())) {
                return true;
            }
        }
    } while ((throwable = throwable.getCause()) != null);
    return false;
}

From source file:org.openmrs.module.webservices.rest.web.RestUtil.java

/**
 * Wraps the exception message as a SimpleObject to be sent to client
 * /*from  ww  w.ja  v  a2 s  .co m*/
 * @param ex
 * @param reason
 * @return
 */
public static SimpleObject wrapErrorResponse(Exception ex, String reason) {
    LinkedHashMap map = new LinkedHashMap();
    if (reason != null && !reason.isEmpty()) {
        map.put("message", reason);
    } else
        map.put("message", ex.getMessage());
    StackTraceElement ste = ex.getStackTrace()[0];
    map.put("code", ste.getClassName() + ":" + ste.getLineNumber());
    map.put("detail", ExceptionUtils.getStackTrace(ex));
    return new SimpleObject().add("error", map);
}

From source file:adalid.core.XS1.java

static boolean checkAccess() {
    String method;//from w ww. jav a  2  s .  c om
    String caller = null;
    final StackTraceElement[] stack = Thread.currentThread().getStackTrace();
    for (StackTraceElement element : stack) {
        method = element.getClassName() + "." + element.getMethodName();
        if (caller == null) {
            if (method.startsWith(ROOT_PACKAGE) && !method.startsWith(THIS_CLASS)) {
                caller = method;
            }
        } else if (method.startsWith(ROOT_PACKAGE)) {
            break;
        } else {
            String message = "illegal invocation of \"" + StringUtils.substringAfterLast(caller, ".") + "\"";
            message += " at " + method + "(" + element.getFileName() + ":" + element.getLineNumber() + ")";
            throw new IllegalAccessRuntimeException(message);
        }
    }
    return caller != null;
}

From source file:ips1ap101.lib.core.app.Bitacora.java

private static String getCallingMethodStackTraceElementTrack(Class clase, String metodo, int argumentos) {
    StackTraceElement trace = getCallingMethodStackTraceElement();
    String traceClassName = trace == null ? null : trace.getClassName();
    String track = getStackTraceElementTrack(trace);
    String firma = clase == null || clase.getName().equals(traceClassName)
            ? getFirmaMetodo("", metodo, argumentos)
            : getFirmaMetodo(clase.getSimpleName(), metodo, argumentos);
    /**///from ww w. j  av  a  2  s. c  o  m
    return firma + track;
}

From source file:org.eclipse.epp.internal.logging.aeri.ui.model.Reports.java

public static Throwable newThrowable(java.lang.Throwable throwable) {
    Throwable mThrowable = factory.createThrowable();
    mThrowable.setMessage(throwable.getMessage());
    mThrowable.setClassName(throwable.getClass().getName());
    List<StackTraceElement> mStackTrace = mThrowable.getStackTrace();
    for (java.lang.StackTraceElement stackTraceElement : throwable.getStackTrace()) {
        StackTraceElement mStackTraceElement = factory.createStackTraceElement();
        mStackTraceElement.setFileName(stackTraceElement.getFileName());
        mStackTraceElement.setClassName(ensureNotBlank(stackTraceElement.getClassName(), throwable));
        mStackTraceElement.setMethodName(ensureNotBlank(stackTraceElement.getMethodName(), throwable));
        mStackTraceElement.setLineNumber(stackTraceElement.getLineNumber());
        mStackTraceElement.setNative(stackTraceElement.isNativeMethod());
        mStackTrace.add(mStackTraceElement);
    }/* www.  jav  a2 s  .c  o m*/
    java.lang.Throwable cause = throwable.getCause();
    if (cause != null) {
        if (cause == throwable) {
            log(WARN_CYCLIC_EXCEPTION, cause.toString());
            return mThrowable;
        }
        mThrowable.setCause(newThrowable(cause));
    }
    return mThrowable;
}