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:org.stenerud.kscrash.KSCrash.java

/** Report a Java exception.
 *
 * @param exception The exception.//from  w  w  w.  ja  va2s  . co  m
 */
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.eluder.logback.ext.jackson.JacksonEncoder.java

protected void writeCallerData(JsonWriter.ObjectWriter<JsonWriter> writer, ILoggingEvent event)
        throws IOException {
    if (event.hasCallerData()) {
        StackTraceElement callerData = event.getCallerData()[0];
        JsonWriter.ObjectWriter<JsonWriter.ObjectWriter<JsonWriter>> ow = writer
                .writeObject(fieldNames.getCallerData(), isActive(fieldNames.getCallerData()));
        ow.writeStringField(fieldNames.getCallerClass(), callerData.getClassName(),
                isActive(fieldNames.getCallerClass()));
        ow.writeStringField(fieldNames.getCallerMethod(), callerData.getMethodName(),
                isActive(fieldNames.getCallerMethod()));
        ow.writeStringField(fieldNames.getCallerFile(), callerData.getFileName(),
                isActive(fieldNames.getCallerFile()));
        ow.writeNumberField(fieldNames.getCallerLine(), callerData.getLineNumber(),
                isActive(fieldNames.getCallerLine()));
        ow.done();//w  w  w .  j a  v  a2  s  . co m
    }
}

From source file:com.gargoylesoftware.htmlunit.SimpleWebTestCase.java

/**
 * Finds from the call stack the active running JUnit test case
 * @return the test case method/*w ww.j  ava  2  s. c o m*/
 * @throws RuntimeException if no method could be found
 */
private Method findRunningJUnitTestMethod() {
    final Class<?> cl = getClass();
    final Class<?>[] args = new Class[] {};

    // search the initial junit test
    final Throwable t = new Exception();
    for (int i = t.getStackTrace().length - 1; i >= 0; i--) {
        final StackTraceElement element = t.getStackTrace()[i];
        if (element.getClassName().equals(cl.getName())) {
            try {
                final Method m = cl.getMethod(element.getMethodName(), args);
                if (isPublicTestMethod(m)) {
                    return m;
                }
            } catch (final Exception e) {
                // can't access, ignore it
            }
        }
    }

    throw new RuntimeException("No JUnit test case method found in call stack");
}

From source file:org.cagrid.identifiers.namingauthority.NamingAuthorityTestCase.java

@Test
public void testRegisterGSID() {
    // System.out.println("testing the RegisterGSID");
    LOG.info("testing testRegisterGSID method");

    // check no register access.
    SecurityInfo secInfo = new SecurityInfoImpl("Unknown");
    try {//from w  ww  .  j a v a2 s.com
        this.NamingAuthority.registerGSID(secInfo, null, null);
        fail("test registerGSID");
    } catch (Exception e) {
        LOG.info("passed registerGSID for " + secInfo.getUser() + ". MSG:\" " + e.getMessage() + "\"");
    }

    secInfo = new SecurityInfoImpl("User13");

    try {
        this.NamingAuthority.registerSite(secInfo, "a", "a", "1.0", "srikalyan", "srikalyan@semanticbits.com",
                "443", "SB");
        LOG.info("passed registerSite inorder to test registerGSID for user " + secInfo.getUser());
    } catch (Exception e) {
        StringBuffer sb = new StringBuffer();
        for (StackTraceElement temp : e.getStackTrace())
            sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n");
        fail("test registeSite for user " + secInfo.getUser() + ". MSG:\"" + sb.toString() + "\"");
    }
    String identifier = null;
    try {
        identifier = this.NamingAuthority.registerGSID(secInfo, null, null);
        LOG.info("passed registerGSID without parent and Identifier for " + secInfo.getUser() + ".");
    } catch (Exception e) {
        fail("test registerGSID without parent and Identifier for " + secInfo.getUser() + ". MSG: \""
                + e.getMessage() + "\"");
    }

    try {
        this.NamingAuthority.registerGSID(secInfo, null, new String[] { identifier, "   ", "" });
        LOG.info("passed test registerGSID with parentIdentifiers not null for " + secInfo.getUser() + ".");
    } catch (Exception e) {
        fail("test registerGSID with parentIdentifiers not null for " + secInfo.getUser() + ". MSG: \""
                + e.getMessage() + "\"");
    }
    identifier = "5784d1dd-9373-533e-8086-fd479fbd564e";
    try {
        identifier = this.NamingAuthority.registerGSID(secInfo, identifier, null);
        LOG.info("passed test registerGSID with suggestedIdentifier not null for " + secInfo.getUser()
                + ". id: " + identifier);
    } catch (Exception e) {
        fail("test registerGSID with suggestedIdentifier not null for " + secInfo.getUser() + ". MSG: \""
                + e.getMessage() + "\"");
    }

    try {
        identifier = this.NamingAuthority.registerGSID(secInfo, identifier,
                new String[] { identifier, "   ", "" });
        fail("test registerGSID with suggestedIdentifier and parent identifiers as not null and with suggestedIdentifier as one of the member in the parent identifier  "
                + secInfo.getUser());
    } catch (Exception e) {
        LOG.info(
                "test registerGSID with suggestedIdentifier and parent identifiers as not null and with suggestedIdentifier as one of the member in the parent identifier "
                        + secInfo.getUser());
    }
}

From source file:org.jtrfp.trcl.TriangleList.java

private void setupVertex(int vIndex, int gpuTVIndex, int triangleIndex, TextureDescription td)
        throws ExecutionException, InterruptedException {
    final int numFrames = getPrimitives().length;
    final Triangle t = triangleAt(0, triangleIndex);
    final Vector3D pos = t.getVertices()[vIndex].getPosition();
    final TriangleVertexWindow vw = (TriangleVertexWindow) getMemoryWindow();
    ////////////////////// V E R T E X //////////////////////////////
    if (numFrames == 1) {
        vw.x.set(gpuTVIndex, (short) applyScale(pos.getX()));
        vw.y.set(gpuTVIndex, (short) applyScale(pos.getY()));
        vw.z.set(gpuTVIndex, (short) applyScale(pos.getZ()));
        final Vector3D normal = t.getVertices()[vIndex].getNormal();
        vw.normX.set(gpuTVIndex, (byte) (normal.getX() * 127));
        vw.normY.set(gpuTVIndex, (byte) (normal.getY() * 127));
        vw.normZ.set(gpuTVIndex, (byte) (normal.getZ() * 127));
    } else {/*  w  w w.j  a  v  a  2s .c om*/
        float[] xFrames = new float[numFrames];
        float[] yFrames = new float[numFrames];
        float[] zFrames = new float[numFrames];
        float[] nxFrames = new float[numFrames];
        float[] nyFrames = new float[numFrames];
        float[] nzFrames = new float[numFrames];
        for (int i = 0; i < numFrames; i++) {
            xFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getX());
        }
        xyzAnimator.addFrames(xFrames);

        for (int i = 0; i < numFrames; i++) {
            yFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getY());
        }
        xyzAnimator.addFrames(yFrames);

        for (int i = 0; i < numFrames; i++) {
            zFrames[i] = (float) applyScale(
                    triangleAt(i, triangleIndex).getVertices()[vIndex].getPosition().getZ());
        }
        xyzAnimator.addFrames(zFrames);

        for (int i = 0; i < numFrames; i++) {
            nxFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getX() * 127);
        }
        xyzAnimator.addFrames(nxFrames);

        for (int i = 0; i < numFrames; i++) {
            nyFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getY() * 127);
        }
        xyzAnimator.addFrames(nyFrames);

        for (int i = 0; i < numFrames; i++) {
            nzFrames[i] = (float) Math
                    .rint(triangleAt(i, triangleIndex).getVertices()[vIndex].getNormal().getZ() * 127);
        }
        xyzAnimator.addFrames(nzFrames);
    } //end else(frames!=1)
      //////////////// T E X T U R E ///////////////////////////
    if (td == null) {
        System.err.println("Stack trace of triangle creation below. NullPointerException follows.");
        for (StackTraceElement el : t.getCreationStackTrace()) {
            System.err.println("\tat " + el.getClassName() + "." + el.getMethodName() + "(" + el.getFileName()
                    + ":" + el.getLineNumber() + ")");
        } //end for(stackTrace)
        throw new NullPointerException("Texture for triangle in " + debugName + " intolerably null.");
    }
    if (td instanceof Texture) {// Static texture
        final int sideScalar = ((Texture) td).getSideLength() - 1;
        if (animateUV && numFrames > 1) {// Animated UV
            float[] uFrames = new float[numFrames];
            float[] vFrames = new float[numFrames];
            final WindowAnimator uvAnimator = new WindowAnimator(getFlatTVWindow(), 2, // UV per vertex
                    numFrames, false, getVertexSequencer(timeBetweenFramesMsec, numFrames),
                    new UVXferFunc(gpuTVIndex * UVXferFunc.BACK_STRIDE_LEN));
            getModel().addTickableAnimator(uvAnimator);
            uvAnimator.setDebugName(debugName + ".uvAnimator");
            for (int i = 0; i < numFrames; i++) {
                uFrames[i] = (float) Math.rint(sideScalar * triangleAt(i, triangleIndex).getUV(vIndex).getX());
                vFrames[i] = (float) Math
                        .rint(sideScalar * (1 - triangleAt(i, triangleIndex).getUV(vIndex).getY()));
            } // end for(numFrames)
            uvAnimator.addFrames(uFrames);
            uvAnimator.addFrames(vFrames);
        } else {// end if(animateUV)
            vw.u.set(gpuTVIndex, (short) Math.rint(sideScalar * t.getUV(vIndex).getX()));
            vw.v.set(gpuTVIndex, (short) Math.rint(sideScalar * (1 - t.getUV(vIndex).getY())));
        } // end if(!animateUV)
        final int textureID = ((Texture) td).getTexturePage();
        vw.textureIDLo.set(gpuTVIndex, (byte) (textureID & 0xFF));
        vw.textureIDMid.set(gpuTVIndex, (byte) ((textureID >> 8) & 0xFF));
        vw.textureIDHi.set(gpuTVIndex, (byte) ((textureID >> 16) & 0xFF));
    } // end if(Texture)
    if (td instanceof AnimatedTexture) {//Animated texture
        final AnimatedTexture at = (AnimatedTexture) td;
        if (animateUV && numFrames > 1) {// Animated UV
            float[] uFrames = new float[numFrames];
            float[] vFrames = new float[numFrames];
            final WindowAnimator uvAnimator = new WindowAnimator(getFlatTVWindow(), 2, // UV per vertex
                    numFrames, false, getVertexSequencer(timeBetweenFramesMsec, numFrames),
                    new UVXferFunc(gpuTVIndex * UVXferFunc.BACK_STRIDE_LEN));
            getModel().addTickableAnimator(uvAnimator);
            for (int i = 0; i < numFrames; i++) {
                final int sideScalar = at.getFrames()[i].getSideLength() - 1;
                uFrames[i] = (float) Math.rint(sideScalar * triangleAt(i, triangleIndex).getUV(vIndex).getX());
                vFrames[i] = (float) Math
                        .rint(sideScalar * (1 - triangleAt(i, triangleIndex).getUV(vIndex).getY()));
            } // end for(numFrames)
            uvAnimator.addFrames(uFrames);
            uvAnimator.addFrames(vFrames);
        } else {// end if(animateUV)
            final int sideScalar = at.getFrames()[0].getSideLength() - 1;
            vw.u.set(gpuTVIndex, (short) Math.rint(sideScalar * t.getUV(vIndex).getX()));
            vw.v.set(gpuTVIndex, (short) Math.rint(sideScalar * (1 - t.getUV(vIndex).getY())));
        } // end if(!animateUV)
        final TexturePageAnimator texturePageAnimator = new TexturePageAnimator(at, vw, gpuTVIndex);
        texturePageAnimator.setDebugName(debugName + ".texturePageAnimator");
        getModel().addTickableAnimator(texturePageAnimator);
    } //end if(animated texture)
}

From source file:de.vandermeer.skb.base.message.Message5WH.java

/**
 * Builder method: sets the Where? part of the message.
 * Three values are taken from the stack trace: class name and method name for the location of Where?
 * and line number for the the line. If the stack trace is null or class name and method are empty, nothing will be
 * set. A line number of 0 will be ignored.
 * @param ste source for the Where? part
 * @return this to allow concatenation//from  w  ww. j  a v  a  2 s. com
 */
public Message5WH setWhere(StackTraceElement ste) {
    if (ste != null) {
        String cn = ste.getClassName();
        String mn = ste.getMethodName();
        int line = ste.getLineNumber();
        //StackTraceElement requires Class and Method set to !null but allows for "", we cope with null but not "" in ST4
        if (!"".equals(cn) || !"".equals(mn)) {
            this.where = this.stg.getInstanceOf("where");
            if (!"".equals(cn)) {
                this.where.add("location", ste.getClassName());
            }
            if (!"".equals(mn)) {
                this.where.add("location", ste.getMethodName());
            }
            if (line > 0) {
                this.where.add("line", ste.getLineNumber());
            }
            //no column information in a stack trace
        }
    }
    return this;
}

From source file:org.seedstack.seed.core.api.SeedException.java

private boolean isInPrintStackTrace() {
    for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) {
        if (JAVA_LANG_THROWABLE.equals(stackTraceElement.getClassName())
                && PRINT_STACK_TRACE.equals(stackTraceElement.getMethodName())) {
            return true;
        }//from   w  w w.j a v a  2 s  .c o  m
    }

    return false;
}

From source file:org.apache.fineract.infrastructure.jobs.service.JobRegisterServiceImpl.java

private String getStackTraceAsString(final Throwable throwable) {
    final StackTraceElement[] stackTraceElements = throwable.getStackTrace();
    final StringBuffer sb = new StringBuffer(throwable.toString());
    for (final StackTraceElement element : stackTraceElements) {
        sb.append("\n \t at ").append(element.getClassName()).append(".").append(element.getMethodName())
                .append("(").append(element.getLineNumber()).append(")");
    }/* w  w w .j  a v a 2  s .  c  o  m*/
    return sb.toString();
}

From source file:info.magnolia.testframework.htmlunit.AbstractMagnoliaHtmlUnitTest.java

/**
 * Need to pass a StackTraceElement to determine the
 * current method, because we can't safely guess at what depth of the stack this method was called.
 * We're keeping this method separate from openPage() for the same reason: if a test/util method
 * calls the openPage method instead of the actual test, the stack won't reflect the "current test method"
 * properly./*ww w  .  j av a  2 s  .  c  o m*/
 */
protected void saveToFile(Page page, StackTraceElement stackTraceElement) throws IOException {
    final WebResponse res = page.getWebResponse();
    InputStream input = res.getContentAsStream();
    final byte[] body = IOUtils.toByteArray(input);
    // TODO : configure the output directory / get it from system properties ?
    final String path = "target/" + stackTraceElement.getClassName() + "-" + stackTraceElement.getMethodName()
            + "-" + stackTraceElement.getLineNumber() + ".out";
    IOUtils.write(body, new FileOutputStream(path));
}

From source file:com.jk.framework.util.FakeRunnable.java

/**
 * Prints the stack trace.//from  w  w w  .  j a v a  2s  .c  o  m
 */
public static void printStackTrace() {
    final Throwable t = new Throwable();
    final StackTraceElement trace[] = t.getStackTrace();
    for (final StackTraceElement element : trace) {
        System.err.println(element.getClassName() + "." + element.getMethodName());
    }

}