List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
From source file:org.codehaus.groovy.grails.exceptions.DefaultStackTraceFilterer.java
private List<StackTraceElement> filterTraceWithCutOff(StackTraceElement[] trace, String endPackage) { List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); boolean foundGroovy = false; for (StackTraceElement stackTraceElement : trace) { String className = stackTraceElement.getClassName(); String fileName = stackTraceElement.getFileName(); if (!foundGroovy && fileName != null && fileName.endsWith(".groovy")) { foundGroovy = true;/*from w w w .j a v a 2s . co m*/ } if (endPackage != null && className.startsWith(endPackage) && foundGroovy) break; if (isApplicationClass(className)) { if (stackTraceElement.getLineNumber() > -1) { newTrace.add(stackTraceElement); } } } return newTrace; }
From source file:io.teak.sdk.Raven.java
public void reportException(Throwable t) { if (t == null) { return;//w ww. j a va 2s .c o m } HashMap<String, Object> additions = new HashMap<>(); ArrayList<Object> exceptions = new ArrayList<>(); HashMap<String, Object> exception = new HashMap<>(); exception.put("type", t.getClass().getSimpleName()); exception.put("value", t.getMessage()); exception.put("module", t.getClass().getPackage().getName()); HashMap<String, Object> stacktrace = new HashMap<>(); ArrayList<Object> stackFrames = new ArrayList<>(); StackTraceElement[] steArray = t.getStackTrace(); for (int i = steArray.length - 1; i >= 0; i--) { StackTraceElement ste = steArray[i]; HashMap<String, Object> frame = new HashMap<>(); frame.put("filename", ste.getFileName()); String method = ste.getMethodName(); if (method.length() != 0) { frame.put("function", method); } int lineno = ste.getLineNumber(); if (!ste.isNativeMethod() && lineno >= 0) { frame.put("lineno", lineno); } String module = ste.getClassName(); frame.put("module", module); boolean in_app = true; if (module.startsWith("android.") || module.startsWith("java.") || module.startsWith("dalvik.") || module.startsWith("com.android.")) { in_app = false; } frame.put("in_app", in_app); stackFrames.add(frame); } stacktrace.put("frames", stackFrames); exception.put("stacktrace", stacktrace); exceptions.add(exception); additions.put("exception", exceptions); try { Report report = new Report(t.getMessage(), Level.ERROR, additions); report.sendToService(); } catch (Exception e) { Log.e(LOG_TAG, "Unable to report Teak SDK exception. " + Log.getStackTraceString(t) + "\n" + Log.getStackTraceString(e)); } }
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 ww w . j a v a 2s . c om*/ */ 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:com.chenxin.authority.common.logback.DBAppender.java
void bindCallerDataWithPreparedStatement(PreparedStatement stmt, StackTraceElement[] callerDataArray) throws SQLException { StackTraceElement callerData = callerDataArray[0]; if (callerData != null) { stmt.setString(CALLER_FILENAME_INDEX, callerData.getFileName()); stmt.setString(CALLER_CLASS_INDEX, callerData.getClassName()); stmt.setString(CALLER_METHOD_INDEX, callerData.getMethodName()); stmt.setString(CALLER_LINE_INDEX, Integer.toString(callerData.getLineNumber())); }/*w ww .j a va 2 s . c o m*/ }
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 {//from w w w. ja v a 2 s. c o m 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:com.zimbra.common.service.ServiceException.java
/** * This is for exceptions that are usually not logged and thus need to include an unique "label" * in the exception id so the thrown(or instantiation) location can be identified by the exception id alone * (without referencing the log - the stack won't be in the log). * * @param callSite call site of the stack where the caller wants to include in the exception id */// ww w . ja va 2 s .c o m public void setIdLabel(StackTraceElement callSite) { String fileName = callSite.getFileName(); int i = fileName.lastIndexOf('.'); if (i != -1) fileName = fileName.substring(0, i); mId = mId + ":" + fileName + callSite.getLineNumber(); }
From source file:op.tools.SYSTools.java
public static String getThrowableAsHTML(Throwable exc) { String html = ""; StackTraceElement[] stacktrace = exc.getStackTrace(); html += SYSConst.html_h1("mail.errormail.attachment.line1"); html += SYSConst.html_h2(exc.getClass().getName()); html += SYSConst.html_paragraph(exc.getMessage()); if (OPDE.getMainframe().getCurrentResident() != null) { html += SYSConst.html_h3("ResID: " + OPDE.getMainframe().getCurrentResident().getRID()); }// w w w. j a v a 2 s . com html += SYSConst.html_h3(OPDE.getMainframe().getCurrentVisiblePanel().getInternalClassID()); String table = SYSConst.html_table_th("mail.errormail.attachment.tab.col1") + SYSConst.html_table_th("mail.errormail.attachment.tab.col2") + SYSConst.html_table_th("mail.errormail.attachment.tab.col3") + SYSConst.html_table_th("mail.errormail.attachment.tab.col4"); for (int exception = 0; exception < stacktrace.length; exception++) { StackTraceElement element = stacktrace[exception]; table += SYSConst.html_table_tr(SYSConst.html_table_td(element.getMethodName()) + SYSConst.html_table_td(Integer.toString(element.getLineNumber())) + SYSConst.html_table_td(element.getClassName()) + SYSConst.html_table_td(element.getFileName())); } html += SYSConst.html_table(table, "1"); // Possible Cause if (exc.getCause() != null) { html += SYSConst.html_h3("Caused by: " + exc.getCause().getMessage()); StackTraceElement[] stacktrace1 = exc.getCause().getStackTrace(); String table1 = SYSConst.html_table_th("mail.errormail.attachment.tab.col1") + SYSConst.html_table_th("mail.errormail.attachment.tab.col2") + SYSConst.html_table_th("mail.errormail.attachment.tab.col3") + SYSConst.html_table_th("mail.errormail.attachment.tab.col4"); for (int exception = 0; exception < stacktrace1.length; exception++) { StackTraceElement element = stacktrace1[exception]; table1 += SYSConst.html_table_tr(SYSConst.html_table_td(element.getMethodName()) + SYSConst.html_table_td(Integer.toString(element.getLineNumber())) + SYSConst.html_table_td(element.getClassName()) + SYSConst.html_table_td(element.getFileName())); } html += SYSConst.html_table(table1, "1"); } return html; }
From source file:Main.java
public static String getCompressedStackTrace(Throwable t, int startAt, int limit) { try {// ww w .j a v a 2s . com StackTraceElement[] stackTrace = t.getStackTrace(); if (stackTrace.length < startAt) { return ""; } StringBuilder sb = new StringBuilder(""); for (int i = startAt; i < stackTrace.length && i < startAt + limit; i++) { StackTraceElement element = stackTrace[i]; String classname = element.getClassName(); String cnShort; boolean showLineNumber = true; boolean breakAfter = false; if (classname.startsWith("com.vuze.android.remote.")) { cnShort = classname.substring(24, classname.length()); } else if (classname.equals("android.os.Handler")) { showLineNumber = false; cnShort = "Handler"; } else if (classname.equals("android.os.Looper")) { showLineNumber = false; cnShort = "Looper"; breakAfter = true; } else if (classname.length() < 9) { // include full if something like aa.ab.ac cnShort = classname; } else { int len = classname.length(); int start = len > 14 ? len - 14 : 0; int pos = classname.indexOf('.', start); if (pos >= 0) { start = pos + 1; } cnShort = classname.substring(start, len); } if (i != startAt) { sb.append(", "); } sb.append(cnShort); sb.append('.'); sb.append(element.getMethodName()); if (showLineNumber) { sb.append(':'); sb.append(element.getLineNumber()); } if (breakAfter) { break; } } Throwable cause = t.getCause(); if (cause != null) { sb.append("\n|Cause "); sb.append(cause.getClass().getSimpleName()); if (cause instanceof Resources.NotFoundException || cause instanceof RuntimeException) { sb.append(' '); sb.append(cause.getMessage()); } sb.append(' '); sb.append(getCompressedStackTrace(cause, 0, 9)); } return sb.toString(); } catch (Throwable derp) { return "derp " + derp.getClass().getSimpleName(); } }
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./*from w w w . j a v a2 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:net.logstash.logback.composite.loggingevent.CallerDataJsonProvider.java
@Override public void writeTo(JsonGenerator generator, ILoggingEvent event) throws IOException { StackTraceElement callerData = extractCallerData(event); if (callerData == null) { return;/*from w w w .j a v a2 s .c o m*/ } if (getFieldName() != null) { generator.writeObjectFieldStart(getFieldName()); } JsonWritingUtils.writeStringField(generator, classFieldName, callerData.getClassName()); JsonWritingUtils.writeStringField(generator, methodFieldName, callerData.getMethodName()); JsonWritingUtils.writeStringField(generator, fileFieldName, callerData.getFileName()); JsonWritingUtils.writeNumberField(generator, lineFieldName, callerData.getLineNumber()); if (getFieldName() != null) { generator.writeEndObject(); } }