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.taobao.adfs.util.Utilities.java

/**
 * not support more override method, ASM is a better solution.
 * refer: http://stackoverflow.com/questions/4024587/get-callers-method-not-name
 *///  w w w  . j a va  2s .c  o  m
public static Method getCaller(boolean staticMethod) throws IOException {
    StackTraceElement caller = Thread.currentThread().getStackTrace()[3];
    Class<?> clazz = ClassCache.getWithIOException(caller.getClassName());
    for (Method method : clazz.getDeclaredMethods()) {
        if (!method.getName().equals(caller.getMethodName()))
            continue;
        if (Modifier.isStatic(method.getModifiers()) != staticMethod)
            continue;
        return method;
    }
    throw new IOException("fail to get caller");
}

From source file:org.eclipse.jubula.client.ui.rcp.Plugin.java

/**
 * checks if the exception is caused by a known GEF problem
 * @param t the Throwable which was caught in the error handler
 * @return true if the exception was cause by an GEF bug
 *//*from  w  w  w  .  j  a v  a 2  s .c om*/
public static boolean isGEFException(Throwable t) {
    Throwable work = t;
    do {
        StackTraceElement[] stack = work.getStackTrace();
        for (StackTraceElement el : stack) {
            // check for
            // org.eclipse.gmf.runtime.diagram.ui.tools.DragEditPartsTrackerEx.addSourceCommands
            if (el.getClassName().indexOf("DragEditPartsTrackerEx") != -1) { //$NON-NLS-1$
                return true;
            }
        }
        work = work.getCause();
    } while (work != null);
    return false;
}

From source file:com.saucelabs.sauce_ondemand.driver.SauceOnDemandSPIImpl.java

/**
 * Try to find the name of the test as best we can.
 *//*ww w .  j a v  a2  s  .  c o  m*/
public String getJobName() {
    // look for the caller of SeleniumFactory
    StackTraceElement[] trace = Thread.currentThread().getStackTrace();
    boolean foundFactory = false;
    String callerName = null;
    for (StackTraceElement e : trace) {
        if (foundFactory)
            callerName = e.getClassName() + "." + e.getMethodName();
        foundFactory = e.getClassName().equals(SeleniumFactory.class.getName());
    }
    return callerName;
}

From source file:org.apromore.service.pql.impl.PQLServiceImpl.java

public List<String> runAPQLQuery(String queryPQL, List<String> IDs, String userID) {
    //Set<String> idNets=new HashSet<>();
    List<String> results = Collections.emptyList();
    IPQLAPI api = pqlBean.getApi();//from   w  w w.  ja  v  a  2  s  .  co m
    LOGGER.error("-----------PQLAPI: " + api);
    LOGGER.error("----------- query: " + queryPQL);
    LOGGER.error("-----------   IDs: " + IDs);
    LOGGER.error("-----------  user: " + userID);
    try {
        PQLQueryResult pqlQueryResult = api.query(queryPQL, new HashSet<>(IDs));
        if (pqlQueryResult.getNumberOfParseErrors() != 0) {
            results = pqlQueryResult.getParseErrorMessages();
        } else {//risultati
            LOGGER.error("-----------IDS PQLServiceImpl" + IDs);
            map = pqlQueryResult.getTaskMap();
            LinkedList<PQLTask> tasks = new LinkedList<>(map.values());
            /*
                            idNets=new HashSet<>(IDs);
                            idNets=api.checkLastQuery(idNets);
                            results.addAll(idNets);
            */
            results = new LinkedList<>(pqlQueryResult.getSearchResults());
            LOGGER.error("-----------QUERYAPQL ESATTA " + results);
        }
    } catch (Exception e) {
        LOGGER.error("-----------ERRORRE: " + e.toString());
        for (StackTraceElement ste : e.getStackTrace())
            LOGGER.info("ERRORE6: " + ste.getClassName() + " " + ste.getMethodName() + " " + ste.getLineNumber()
                    + " " + ste.getFileName());
    }
    return results;
}

From source file:minium.script.rhinojs.RhinoEngine.java

protected StackTraceElement[] process(StackTraceElement[] stackTrace) {
    List<StackTraceElement> processed = Lists.newArrayList();
    for (StackTraceElement element : stackTrace) {
        if (element.getClassName().startsWith("org.mozilla.javascript.gen") && element.getLineNumber() != -1) {
            String fileName = null;
            File file = new File(element.getFileName());
            if (file.exists() && file.isFile()) {
                fileName = file.getAbsolutePath();
            }//  w  w w . ja  va  2s  .co m
            if (fileName == null)
                fileName = element.getFileName();
            processed.add(new StackTraceElement(element.getClassName(), element.getMethodName(), fileName,
                    element.getLineNumber()));
        }
    }
    return processed.toArray(new StackTraceElement[processed.size()]);
}

From source file:org.apache.maven.surefire.its.fixture.MavenLauncher.java

private StackTraceElement findTopElemenent(StackTraceElement[] stackTrace, Class testClassToLookFor) {
    StackTraceElement bestmatch = null;
    for (StackTraceElement stackTraceElement : stackTrace) {
        if (stackTraceElement.getClassName().equals(testClassToLookFor.getName())) {
            bestmatch = stackTraceElement;
        }/*  w  ww .  j  av  a2s  .co  m*/
    }
    return bestmatch;
}

From source file:com.summer.logger.LoggerPrinter.java

  /**
 * Determines the starting index of the stack trace, after method calls made by this class.
 *
 * @param trace the stack trace//from www. j a v  a 2s  . c o m
 * @return the stack offset
 */
private int getStackOffset(StackTraceElement[] trace) {
  for (int i = MIN_STACK_OFFSET; i < trace.length; i++) {
    StackTraceElement e = trace[i];
    String name = e.getClassName();
    if (!name.equals(LoggerPrinter.class.getName()) && !name.equals(Logger.class.getName())) {
      return --i;
    }
  }
  return -1;
}

From source file:eu.europa.esig.dss.DSSUtils.java

/**
 * This method returns the summary of the given exception. The analysis of the stack trace stops when the provided class is found.
 *
 * @param exception/*from ww w.j  a v a 2s.c  o  m*/
 *            {@code Exception} to summarize
 * @param javaClass
 *            {@code Class}
 * @return {@code String} containing the summary message
 */
public static String getSummaryMessage(final Exception exception, final Class<?> javaClass) {

    final String javaClassName = javaClass.getName();
    final StackTraceElement[] stackTrace = exception.getStackTrace();
    String message = "See log file for full stack trace.\n";
    message += exception.toString() + '\n';
    for (StackTraceElement element : stackTrace) {

        final String className = element.getClassName();
        if (className.equals(javaClassName)) {

            message += element.toString() + '\n';
            break;
        }
        message += element.toString() + '\n';
    }
    return message;
}

From source file:org.openmrs.module.privilegehelper.PrivilegeLogger.java

/**
 * Inspects the stack trace to find a place where the privilege was checked
 * //w  ww.  j  a  va 2  s .  c o m
 * @return the class.method or <code>null</code> if it cannot be found
 */
private StackTraceInfo inspectStackTrace() {
    final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    boolean requiredPrivilege = false;
    for (int i = 0; i < stackTrace.length; i++) {
        final StackTraceElement unrelatedElement = stackTrace[i];

        if (UserContext.class.getName().equals(unrelatedElement.getClassName())
                && "hasPrivilege".equals(unrelatedElement.getMethodName())) {

            for (int j = i + 1; j < stackTrace.length; j++) {
                final StackTraceElement element = stackTrace[j];

                if (element.getFileName() != null && element.getFileName().endsWith("_jsp")) {
                    String jsp = element.getFileName();
                    int indexOfView = jsp.indexOf("view");
                    if (indexOfView > 0) {
                        jsp = jsp.substring(indexOfView);
                    }
                    jsp = jsp.replace(".", "/");
                    jsp = jsp.replace("_", ".");

                    return new StackTraceInfo(jsp, requiredPrivilege);
                }

                if (!element.getClassName().startsWith("org.openmrs")) {
                    continue;
                }

                //Determine if it is a required privilege or a simple check
                if (RequireTag.class.getName().equals(element.getClassName())) {
                    requiredPrivilege = true;
                    continue;
                }
                if (PrivilegeTag.class.getName().equals(element.getClassName())) {
                    requiredPrivilege = false;
                    continue;
                }
                if (AuthorizationAdvice.class.getName().equals(element.getClassName())) {
                    requiredPrivilege = true;
                    continue;
                }
                if (Context.class.getName().equals(element.getClassName())) {
                    if ("requirePrivilege".equals(element.getMethodName())) {
                        requiredPrivilege = true;
                    }
                    continue;
                }

                try {
                    final Class<?> clazz = OpenmrsClassLoader.getInstance().loadClass(element.getClassName());

                    if (clazz.isAnnotationPresent(Controller.class)) {
                        String url = "";

                        final RequestMapping clazzRequestMapping = clazz.getAnnotation(RequestMapping.class);
                        if (clazzRequestMapping != null) {
                            url = clazzRequestMapping.value()[0];
                        }

                        final Method[] methods = clazz.getMethods();
                        for (Method method : methods) {
                            if (method.getName().equals(element.getMethodName())) {
                                final RequestMapping requestMapping = method
                                        .getAnnotation(RequestMapping.class);
                                if (requestMapping != null) {
                                    url += requestMapping.value()[0];
                                }
                                break;
                            }
                        }

                        if (url.isEmpty()) {
                            return new StackTraceInfo(element.toString(), requiredPrivilege);
                        } else {
                            return new StackTraceInfo(element.toString() + ", URL: " + url, requiredPrivilege);
                        }
                    }
                } catch (ClassNotFoundException e) {
                }

                return new StackTraceInfo(element.toString(), requiredPrivilege);
            }
        }
    }
    return null;
}

From source file:com.bstek.dorado.view.resolver.ViewServiceResolver.java

/**
 * @param jsonBuilder//from www . j ava2s .  com
 * @param e
 */
protected void outputException(JsonBuilder jsonBuilder, Throwable throwable) {
    while (throwable.getCause() != null) {
        throwable = throwable.getCause();
    }

    String message = throwable.getMessage();
    if (message == null) {
        message = throwable.getClass().getSimpleName();
    }

    try {
        jsonBuilder.object(); // TODO: ?JSONBuilder?
        jsonBuilder.key("exceptionType").value("JavaException").key("message").value(message).key("stackTrace");
        jsonBuilder.array();
        StackTraceElement[] stackTrace = throwable.getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            jsonBuilder.value(stackTraceElement.getClassName() + '.' + stackTraceElement.getMethodName() + '('
                    + stackTraceElement.getFileName() + ':' + stackTraceElement.getLineNumber() + ')');
        }
        jsonBuilder.endArray();
        jsonBuilder.endObject();
    } catch (Exception e) {
        // ignore e!!!
        throwable.printStackTrace();
    }
}