Example usage for java.lang StackTraceElement getMethodName

List of usage examples for java.lang StackTraceElement getMethodName

Introduction

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

Prototype

public String getMethodName() 

Source Link

Document

Returns the name of the method containing the execution point represented by this stack trace element.

Usage

From source file:io.hops.metadata.util.RMUtilities.java

public static String getCallerMethod(String className) {
    StackTraceElement[] elements = Thread.currentThread().getStackTrace();
    StringBuilder sb = new StringBuilder();
    sb.append(", caller-");
    for (StackTraceElement elem : elements) {
        if (elem.getClassName().contains(className)) {
            sb.append(elem.getClassName());
            sb.append("-");
            sb.append(elem.getMethodName());
        }//  w ww. ja  v  a 2 s .  co m
    }
    return sb.toString();
}

From source file:org.codelibs.fess.web.base.FessBaseAction.java

protected void buildApplicationExceptionStackTrace(RuntimeException cause, StringBuilder sb) {
    final StackTraceElement[] stackTrace = cause.getStackTrace();
    if (stackTrace == null) { // just in case
        return;//from  ww w  .j ava  2  s.  co m
    }
    int index = 0;
    for (StackTraceElement element : stackTrace) {
        if (index > 10) { // not all because it's not error
            break;
        }
        final String className = element.getClassName();
        final String fileName = element.getFileName(); // might be null
        final int lineNumber = element.getLineNumber();
        final String methodName = element.getMethodName();
        sb.append("\n at ").append(className).append(".").append(methodName);
        sb.append("(").append(fileName);
        if (lineNumber >= 0) {
            sb.append(":").append(lineNumber);
        }
        sb.append(")");
        ++index;
    }
}

From source file:org.apache.flink.client.CliFrontend.java

/**
 * Displays an exception message.// w  w w. jav a 2  s  .c o  m
 * 
 * @param t The exception to display.
 * @return The return code for the process.
 */
private int handleError(Throwable t) {
    LOG.error("Error while running the command.", t);

    System.err.println();
    System.err.println("------------------------------------------------------------");
    System.err.println(" The program finished with the following exception:");
    System.err.println();

    if (t.getCause() instanceof InvalidProgramException) {
        System.err.println(t.getCause().getMessage());
        StackTraceElement[] trace = t.getCause().getStackTrace();
        for (StackTraceElement ele : trace) {
            System.err.println("\t" + ele.toString());
            if (ele.getMethodName().equals("main")) {
                break;
            }
        }
    } else {
        t.printStackTrace();
    }
    return 1;
}

From source file:org.apache.sysml.runtime.instructions.gpu.context.JCudaObject.java

private String getClassAndMethod(StackTraceElement st) {
    String[] str = st.getClassName().split("\\.");
    return str[str.length - 1] + "." + st.getMethodName();
}

From source file:com.yourkey.billing.util.InAppBilling.java

private String getErrorLocation(int stackFrame) {
    StackTraceElement element = new Throwable().getStackTrace()[stackFrame + 1];
    String className = element.getClassName();
    if (className.startsWith(packageName + "."))
        className = className.substring(packageName.length() + 1);
    return ("Error location: " + element.getFileName() + " (" + Integer.toString(element.getLineNumber())
            + ")\n" + className + "." + element.getMethodName());
}

From source file:com.ibm.xsp.webdav.resource.DAVResourceDominoCategorizedDocuments.java

private String trace(StackTraceElement e[], int level) {
    if (e != null && e.length >= level) {
        StackTraceElement s = e[level];
        if (s != null) {
            return s.getMethodName();
        }//from ww w  .  ja  v  a  2 s. c  om
    }
    return null;
}

From source file:com.qspin.qtaste.ui.reporter.TestCaseReportTable.java

protected void updateTestCaseRow(TestResult tr) {

    int rowNum = ((Integer) testCases.get(tr)).intValue();
    if (rowNum == -1) {
        // means that testcases has not been emptied ..

        // TO DO/*from   w w w .  j av  a2  s . c om*/
        return;
    }
    tcModel.setValueAt(convertToUniqueTc(tr), rowNum, TEST_CASE);
    tcModel.setValueAt(tr.getFormattedElapsedTime(false), rowNum, EXEC_TIME);
    tcModel.setValueAt(tr.getExtraResultDetails(), rowNum, DETAILS);
    if (tr.getReturnValue() != null) {
        tcModel.setValueAt(tr.getReturnValue(), rowNum, RESULT);
    }

    TestResult.Status testCaseStatus = tr.getStatus();
    ImageIcon statusImg = getImage(testCaseStatus);
    tcModel.setValueAt(statusImg, rowNum, STATUS);

    TestBedConfiguration testbed = TestBedConfiguration.getInstance();
    tcModel.setValueAt(
            testbed.getFile().getName().replace("." + StaticConfiguration.CAMPAIGN_FILE_EXTENSION, ""), rowNum,
            TESTBED);

    if ((testCaseStatus == TestResult.Status.FAIL) || ((testCaseStatus == TestResult.Status.NOT_AVAILABLE))) {
        int selectedRow = tcTable.getSelectedRow();
        // update the failedReason if the current selected testcase is
        //   the one to be updated
        if (selectedRow == rowNum) {
            if (tcReasonModel != null) {
                // clear
                while (tcReasonModel.getRowCount() > 0) {
                    tcReasonModel.removeRow(0);
                }
                ArrayList<StackTraceElement> stack = tr.getStack();
                Iterator<StackTraceElement> it = stack.iterator();
                while (it.hasNext()) {
                    StackTraceElement stackElement = it.next();
                    if (stackElement.getFileName().equals("embedded_jython")) {
                        continue;
                    }
                    Object[] row = new Object[6];
                    row[TCResultsSelectionListeners.LINE] = stackElement.getLineNumber();
                    row[TCResultsSelectionListeners.FILE_NAME] = stackElement.getFileName();
                    String methodName = stackElement.getMethodName();
                    if (methodName.equals("f$0")) {
                        methodName = "main";
                    } else {
                        // remove $i suffix from method name
                        int dollarIndex = methodName.indexOf("$");
                        if (dollarIndex > 0) {
                            methodName = methodName.substring(0, dollarIndex);
                        }
                    }
                    row[TCResultsSelectionListeners.FUNCTION_ID] = methodName;
                    //row[TCResultsSelectionListeners.ERR_MSG] = tr.getExtraResultDetails();
                    row[TCResultsSelectionListeners.OBJECT] = stackElement;
                    //row[TCResultsSelectionListeners.ROW] = tr.getTestData() != null ? tr.getTestData().getRowId() : null;;
                    tcReasonModel.addRow(row);
                }
            }
            if (stackTrace != null) {
                stackTrace.setText(tr.getStackTrace());
            }
        }
    }
}

From source file:org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceHelperServiceImpl.java

/**
 * @param element//from   w  w w  .  java2 s . c  om
 * @return String describing the given StackTraceElement
 */
private static String describeStackTraceElement(StackTraceElement element) {
    StringBuffer description = new StringBuffer();
    if (element == null) {
        description.append("invalid (null) element");
    }
    description.append(element.getClassName());
    description.append(".");
    description.append(element.getMethodName());
    description.append("(");
    description.append(element.getFileName());
    description.append(":");
    description.append(element.getLineNumber());
    description.append(")");

    return description.toString();
}

From source file:com.evolveum.icf.dummy.resource.DummyResource.java

private void traceOperation(String opName, long counter) {
    LOGGER.info("MONITOR dummy '{}' {} ({})", instanceName, opName, counter);
    if (LOGGER.isDebugEnabled()) {
        StackTraceElement[] fullStack = Thread.currentThread().getStackTrace();
        String immediateClass = null;
        String immediateMethod = null;
        StringBuilder sb = new StringBuilder();
        for (StackTraceElement stackElement : fullStack) {
            if (stackElement.getClassName().equals(DummyResource.class.getName())
                    || stackElement.getClassName().equals(Thread.class.getName())) {
                // skip our own calls
                continue;
            }/*w  w  w.ja va  2s . c  o m*/
            if (immediateClass == null) {
                immediateClass = stackElement.getClassName();
                immediateMethod = stackElement.getMethodName();
            }
            sb.append(stackElement.toString());
            sb.append("\n");
        }
        LOGGER.debug("MONITOR dummy '{}' {} ({}): {} {}",
                new Object[] { instanceName, opName, counter, immediateClass, immediateMethod });
        LOGGER.trace("MONITOR dummy '{}' {} ({}):\n{}", new Object[] { instanceName, opName, counter, sb });
    }
}

From source file:com.itemanalysis.psychometrics.optimization.BOBYQAOptimizer.java

private static String caller(int n) {
    final Throwable t = new Throwable();
    final StackTraceElement[] elements = t.getStackTrace();
    final StackTraceElement e = elements[n];
    return e.getMethodName() + " (at line " + e.getLineNumber() + ")";
}