List of usage examples for java.lang StackTraceElement getLineNumber
public int getLineNumber()
From source file:org.nuclos.server.ruleengine.ejb3.RuleEngineFacadeBean.java
private int getErrorLineNumber(Exception ex, int iHeaderLinesCount) { int iErrorLineNumber = 0; for (StackTraceElement stackElement : ex.getStackTrace()) { if (stackElement.getClassName().startsWith("Rule_")) { iErrorLineNumber = stackElement.getLineNumber(); break; }//from www . j av a 2s.co m } return iErrorLineNumber > 0 ? (iErrorLineNumber - iHeaderLinesCount) : 0; }
From source file:org.kuali.kfs.module.purap.service.impl.ElectronicInvoiceHelperServiceImpl.java
/** * @param element//from w w w.j ava 2s. c o m * @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.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() + ")"; }
From source file:org.zywx.wbpalmstar.engine.EBrowserView.java
protected void printThreadStackTrace() { StackTraceElement[] stak = Thread.currentThread().getStackTrace(); String s = ""; int len = stak.length; for (int i = 0; i < len; ++i) { StackTraceElement one = stak[i]; String className = one.getClassName(); String methodName = one.getMethodName(); int line = one.getLineNumber(); String x = s + className + "." + methodName + " [" + line + "]"; x.charAt(0);/*from w w w .j a v a 2 s . c o m*/ if (i == 0 || i == 1 || i == 2) { s += " "; } } }
From source file:org.csploit.android.core.UpdateService.java
@Override protected void onHandleIntent(Intent intent) { action what_to_do = (action) intent.getSerializableExtra(ACTION); boolean exitForError = true; if (what_to_do == null) { Logger.error("received null action"); return;/* w w w .j a v a2s. c om*/ } mRunning = true; switch (what_to_do) { case apk_update: mCurrentTask = mApkInfo; break; case core_update: mCurrentTask = mCoreInfo; break; case ruby_update: mCurrentTask = mRubyInfo; break; case msf_update: mCurrentTask = mMsfInfo; break; case gems_update: mCurrentTask = new ArchiveMetadata(); break; } try { setupNotification(); synchronized (mCurrentTask) { mCurrentTask.errorOccurred = true; if (!haveLocalFile()) downloadFile(); if (what_to_do == action.core_update) System.shutdownCoreDaemon(); extract(); if (what_to_do == action.msf_update) installGems(); else if (what_to_do == action.gems_update) updateGems(); else if (what_to_do == action.core_update) System.initCore(); deleteTemporaryFiles(); createVersionFile(); mCurrentTask.errorOccurred = exitForError = false; } sendDone(what_to_do); } catch (SecurityException e) { sendError(what_to_do, R.string.bad_permissions); Logger.warning(e.getClass().getName() + ": " + e.getMessage()); } catch (KeyException e) { sendError(what_to_do, R.string.checksum_failed); Logger.warning(e.getClass().getName() + ": " + e.getMessage()); } catch (NoSuchAlgorithmException e) { sendError(what_to_do, R.string.error_occured); System.errorLogging(e); } catch (CancellationException e) { sendError(what_to_do, R.string.update_cancelled); Logger.warning(e.getClass().getName() + ": " + e.getMessage()); } catch (IOException e) { sendError(what_to_do, R.string.error_occured); System.errorLogging(e); } catch (RuntimeException e) { sendError(what_to_do, R.string.error_occured); StackTraceElement[] stack = e.getStackTrace(); StackTraceElement frame = e.getStackTrace()[0]; for (StackTraceElement f : stack) { if (f.getClassName().startsWith("org.csploit.android")) { frame = f; break; } } Logger.error(String.format("%s: %s [%s:%d]", e.getClass().getName(), e.getMessage(), frame.getFileName(), frame.getLineNumber())); } catch (InterruptedException e) { sendError(what_to_do, R.string.error_occured); System.errorLogging(e); } catch (ChildManager.ChildNotStartedException e) { sendError(what_to_do, R.string.error_occured); System.errorLogging(e); } catch (ChildManager.ChildDiedException e) { sendError(what_to_do, R.string.error_occured); System.errorLogging(e); } catch (System.SuException e) { sendError(what_to_do, R.string.only_4_root); } catch (System.DaemonException e) { sendError(what_to_do, R.string.heart_attack); Logger.error(e.getMessage()); } finally { if (exitForError) { if (what_to_do == action.msf_update || what_to_do == action.gems_update) clearGemsCache(); if (what_to_do != action.core_update) wipe(); } stopSelf(); mRunning = false; } }
From source file:edu.isi.wings.ontapi.jena.KBAPIJena.java
private boolean checkNulls(Object... vars) { for (Object var : vars) { if (var == null) { StackTraceElement[] stack = Thread.currentThread().getStackTrace(); StackTraceElement method = stack[2]; StackTraceElement caller = stack[3]; String warnstr = method.getMethodName() + ": " + Arrays.toString(vars); warnstr += ", called from " + caller.getFileName() + ":" + caller.getLineNumber(); Logger.getLogger(this.getClass()).warn(warnstr); return false; }/* w w w . j ava2 s . c o m*/ } return true; }
From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java
private void logXEntry() { Exception e = new Exception(); StackTraceElement se = e.getStackTrace()[1]; M_log.info("Log marker " + se.getMethodName() + ":" + se.getFileName() + ":" + se.getLineNumber()); }
From source file:edu.umd.cs.marmoset.modelClasses.TestOutcome.java
private boolean coversLineOrPreviousLines(StackTraceElement stackTraceElement, int range, CodeCoverageResults coverage) throws IOException { // If we weren't able to extract a stack trace for some reason, then simply return false if (stackTraceElement == null) return false; if (!isCoverageType()) return false; FileWithCoverage fileWithCoverage = coverage.getFileWithCoverage(stackTraceElement.getFileName()); if (fileWithCoverage == null) { // ERROR: Can't find the appropriate file in this set of coverage results System.err.println("No coverage for " + stackTraceElement.getFileName()); return false; }/*from w w w. ja v a2s.co m*/ for (int ii = stackTraceElement.getLineNumber(); ii >= stackTraceElement.getLineNumber() - range; ii--) { if (fileWithCoverage.isLineCovered(ii)) return true; } return false; }
From source file:com.simiacryptus.util.io.MarkdownNotebookOutput.java
@Override @SuppressWarnings("unchecked") public <T> T code(@javax.annotation.Nonnull final UncheckedSupplier<T> fn, final int maxLog, final int framesNo) { try {//from w ww . ja v a2 s . c o m final StackTraceElement callingFrame = Thread.currentThread().getStackTrace()[framesNo]; final String sourceCode = CodeUtil.getInnerText(callingFrame); @javax.annotation.Nonnull final SysOutInterceptor.LoggedResult<TimedResult<Object>> result = SysOutInterceptor.withOutput(() -> { long priorGcMs = ManagementFactory.getGarbageCollectorMXBeans().stream() .mapToLong(x -> x.getCollectionTime()).sum(); final long start = System.nanoTime(); try { @Nullable Object result1 = null; try { result1 = fn.get(); } catch (@javax.annotation.Nonnull final RuntimeException e) { throw e; } catch (@javax.annotation.Nonnull final Exception e) { throw new RuntimeException(e); } long gcTime = ManagementFactory.getGarbageCollectorMXBeans().stream() .mapToLong(x -> x.getCollectionTime()).sum() - priorGcMs; return new TimedResult<Object>(result1, System.nanoTime() - start, gcTime); } catch (@javax.annotation.Nonnull final Throwable e) { long gcTime = ManagementFactory.getGarbageCollectorMXBeans().stream() .mapToLong(x -> x.getCollectionTime()).sum() - priorGcMs; return new TimedResult<Object>(e, System.nanoTime() - start, gcTime); } }); out(anchor(anchorId()) + "Code from [%s:%s](%s#L%s) executed in %.2f seconds (%.3f gc): ", callingFrame.getFileName(), callingFrame.getLineNumber(), linkTo(CodeUtil.findFile(callingFrame)), callingFrame.getLineNumber(), result.obj.seconds(), result.obj.gc_seconds()); String text = sourceCode.replaceAll("\n", "\n "); out("```java"); out(" " + text); out("```"); if (!result.log.isEmpty()) { String summary = summarize(result.log, maxLog).replaceAll("\n", "\n ").replaceAll(" ~", ""); out(anchor(anchorId()) + "Logging: "); out("```"); out(" " + summary); out("```"); } out(""); final Object eval = result.obj.result; if (null != eval) { out(anchor(anchorId()) + "Returns: \n"); String str; boolean escape; if (eval instanceof Throwable) { @javax.annotation.Nonnull final ByteArrayOutputStream out = new ByteArrayOutputStream(); ((Throwable) eval).printStackTrace(new PrintStream(out)); str = new String(out.toByteArray(), "UTF-8"); escape = true;// } else if (eval instanceof Component) { str = image(Util.toImage((Component) eval), "Result"); escape = false; } else if (eval instanceof BufferedImage) { str = image((BufferedImage) eval, "Result"); escape = false; } else if (eval instanceof TableOutput) { str = ((TableOutput) eval).toTextTable(); escape = false; } else { str = eval.toString(); escape = true; } @javax.annotation.Nonnull String fmt = escape ? " " + summarize(str, maxLog).replaceAll("\n", "\n ").replaceAll(" ~", "") : str; if (escape) { out("```"); out(fmt); out("```"); } else { out(fmt); } out("\n\n"); if (eval instanceof RuntimeException) { throw ((RuntimeException) result.obj.result); } if (eval instanceof Throwable) { throw new RuntimeException((Throwable) result.obj.result); } } return (T) eval; } catch (@javax.annotation.Nonnull final IOException e) { throw new RuntimeException(e); } }