Example usage for java.lang StackTraceElement getLineNumber

List of usage examples for java.lang StackTraceElement getLineNumber

Introduction

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

Prototype

public int getLineNumber() 

Source Link

Document

Returns the line number of the source line containing the execution point represented by this stack trace element.

Usage

From source file:adalid.core.XS1.java

static boolean checkAccess() {
    String method;/*from www  .  j  av a  2  s.c  o m*/
    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:org.collectionspace.chain.csp.webui.main.StreamUIRequest.java

private void exception_to_text_internal(StringBuffer buf, Throwable e) {
    buf.append("Exception " + e.getClass() + " thrown message=\"" + e.getMessage() + "\"\n");
    for (StackTraceElement el : e.getStackTrace()) {
        buf.append(el.getClassName() + " " + el.getMethodName() + " (" + el.getFileName() + ":"
                + el.getLineNumber() + ")\n");
    }/* w ww.  j  av a 2s . c  om*/
    Throwable next = e.getCause();
    if (next != null && next != e) {
        buf.append("Caused by:\n");
        exception_to_text_internal(buf, next);
    }
}

From source file:org.stenerud.kscrash.KSCrash.java

/** Report a Java exception.
 *
 * @param exception The exception./*  w ww .j  a v a  2  s .c om*/
 */
public void reportJavaException(Throwable exception) {
    try {
        JSONArray array = new JSONArray();
        for (StackTraceElement element : exception.getStackTrace()) {
            JSONObject object = new JSONObject();
            object.put("file", element.getFileName());
            object.put("line", element.getLineNumber());
            object.put("class", element.getClassName());
            object.put("method", element.getMethodName());
            object.put("native", element.isNativeMethod());
            array.put(object);
        }
        reportUserException(exception.getClass().getName(), exception.getMessage(), "java",
                exception.getStackTrace()[0].getFileName(), exception.getStackTrace()[0].getLineNumber(), array,
                false, false);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:org.jtrfp.trcl.flow.GameShell.java

private void throwable2StringBuilder(Throwable e, StringBuilder sb) {
    assert e != null;
    assert sb != null;
    sb.append(e.getClass().getName() + " " + e.getLocalizedMessage() + "\n");
    final StackTraceElement[] stackTraceElements = e.getStackTrace();
    for (StackTraceElement ste : stackTraceElements)
        sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":"
                + ste.getLineNumber() + ")\n");
}

From source file:jp.co.opentone.bsol.framework.web.view.action.ActionHandler.java

private void logServiceAbortException(ServiceAbortException e) {
    StackTraceElement[] elem = e.getStackTrace();
    if (elem != null && elem.length > 0) {
        try {//from   ww w  .jav  a  2s  .  c  o  m
            StackTraceElement element = elem[0];
            String format = "%s.%s:%d [%s]";
            log.warn(String.format(format, getSimpleClassName(element.getClassName()), element.getMethodName(),
                    element.getLineNumber(), e.getMessageCode()));
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
        }
    }
}

From source file:org.kuali.rice.krad.uif.util.CopyUtils.java

/**
 * Mix-in copy implementation for objects that implement the {@link Copyable} interface}
 * //from w  w  w . j  a v  a2s. co  m
 * @param <T> copyable type
 * @param obj The object to copy.
 * @return A deep copy of the object.
 */
@SuppressWarnings("unchecked")
public static <T> T copy(Copyable obj) {
    if (obj == null) {
        return null;
    }

    String cid = null;
    if (ViewLifecycle.isTrace()) {
        StackTraceElement[] trace = Thread.currentThread().getStackTrace();
        int i = 3;
        while (ComponentUtils.class.getName().equals(trace[i].getClassName()))
            i++;
        StackTraceElement caller = trace[i];
        cid = obj.getClass().getSimpleName() + ":" + caller.getClassName() + ":" + caller.getMethodName() + ":"
                + caller.getLineNumber();
        ProcessLogger.ntrace("deep-copy:", ":" + cid, 1000L, 500L);
    }

    return (T) getDeepCopy(obj);
}

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();/*  w  ww. ja v  a  2s  . c o 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:com.stackify.log.log4j2.LogEventAdapter.java

/**
 * @see com.stackify.api.common.log.EventAdapter#getLogMsg(java.lang.Object, com.google.common.base.Optional)
 *///from  w  w  w .  j  av a2 s .c o m
@Override
public LogMsg getLogMsg(final LogEvent event, final StackifyError error) {

    LogMsg.Builder builder = LogMsg.newBuilder();

    builder.msg(getMessage(event));

    Map<String, String> props = getProperties(event);

    if (!props.isEmpty()) {
        try {
            builder.data(json.writeValueAsString(props));
        } catch (Exception e) {
            // do nothing
        }
    }

    builder.ex(error);
    builder.th(event.getThreadName());
    builder.epochMs(event.getTimeMillis());
    builder.level(event.getLevel().toString().toLowerCase());

    String transactionId = APMLogData.isLinked() ? APMLogData.getTransactionId()
            : ServletLogContext.getTransactionId();

    if (transactionId != null) {
        builder.transId(transactionId);
    }

    StackTraceElement source = event.getSource();

    if (source != null) {
        builder.srcMethod(source.getClassName() + "." + source.getMethodName());

        try {
            builder.srcLine(source.getLineNumber());
        } catch (Throwable e) {
        }
    }

    return builder.build();
}

From source file:gov.nih.nci.cagrid.identifiers.test.StressTestUtil.java

public void testOnlyRegisterGSID(long numberOfTests) {
    List<String> identifiers = new ArrayList<String>();

    String suggestedIdentifier = null;
    int randomNumber;
    for (long i = 0l; i < numberOfTests; i++) {
        randomNumber = rand.nextInt(20);
        String parentIdentifiers[] = null;
        // 2 parents 5%
        if (randomNumber == 0 && identifiers.size() > 2) {
            int firstIdIndex = rand.nextInt(identifiers.size());
            int secondIdIndex = rand.nextInt(identifiers.size());
            while (secondIdIndex == firstIdIndex)
                secondIdIndex = rand.nextInt(identifiers.size());
            parentIdentifiers = new String[] { identifiers.get(firstIdIndex), identifiers.get(secondIdIndex) };
        }//ww w.ja  v a  2  s  .  c o  m
        // 1 parent 25 %
        else if (identifiers.size() > 0 && randomNumber % 4 == 1) {
            int firstIdIndex = rand.nextInt(identifiers.size());
            parentIdentifiers = new String[] { identifiers.get(firstIdIndex) };
        }

        try {
            String identifier = testUtil.registerGSID(suggestedIdentifier, parentIdentifiers);
            // if(i%100==0)
            // System.out.println(i);
            addElement2List(identifiers, identifier);
            writeToFile(identifier);
        } catch (Exception e) {
            System.out.println("exception occured1 " + e.getMessage());
            e.printStackTrace();
            StringBuffer sb = new StringBuffer();
            for (StackTraceElement temp : e.getStackTrace())
                sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n");
            log.debug("exception occured \n" + sb.toString());
        }
    }
}

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();
            }/*from ww  w.jav a 2 s  .c  om*/
            if (fileName == null)
                fileName = element.getFileName();
            processed.add(new StackTraceElement(element.getClassName(), element.getMethodName(), fileName,
                    element.getLineNumber()));
        }
    }
    return processed.toArray(new StackTraceElement[processed.size()]);
}