List of usage examples for java.lang StackTraceElement getClassName
public String getClassName()
From source file:org.rhq.core.pc.inventory.AvailabilityExecutor.java
static private String getSmallStackTrace(Throwable t) { StringBuilder smallStack = new StringBuilder(); StackTraceElement[] stack = (null == t) ? new Exception().getStackTrace() : t.getStackTrace(); for (int i = 1; i < stack.length; i++) { StackTraceElement ste = stack[i]; if (ste.getClassName().startsWith("org.rhq")) { smallStack.append(ste.toString()); smallStack.append("\n"); }/*from w ww . j ava2 s. co m*/ } return smallStack.toString(); }
From source file:schemacrawler.test.utility.TestUtility.java
private static Path buildDirectory() throws Exception { final StackTraceElement ste = currentMethodStackTraceElement(); final Class<?> callingClass = Class.forName(ste.getClassName()); final Path codePath = Paths.get(callingClass.getProtectionDomain().getCodeSource().getLocation().toURI()) .normalize().toAbsolutePath(); final boolean isInTarget = codePath.toString().contains("target"); if (!isInTarget) { throw new RuntimeException("Not in build directory, " + codePath); }/*w w w . j a v a2 s. co m*/ final Path directory = codePath.resolve(".."); return directory.normalize().toAbsolutePath(); }
From source file:it.tidalwave.northernwind.frontend.ui.component.blog.DefaultBlogViewController.java
/******************************************************************************************************************* * * ******************************************************************************************************************/ private static boolean isCalledBySitemapController() { for (final StackTraceElement element : Thread.currentThread().getStackTrace()) { if (element.getClassName().contains("SitemapViewController")) { return true; }/*www . java 2 s. c om*/ } return false; }
From source file:org.eclipse.wb.internal.core.DesignerPlugin.java
/** * We should not allow user code to terminate JVM. *///w w w. ja va2 s .c o m public static void installSecurityManager() { System.setSecurityManager(new SecurityManager() { @Override public void checkPermission(java.security.Permission perm) { if (isExitVM(perm)) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement element : stackTrace) { String className = element.getClassName(); String methodName = element.getMethodName(); // ignore this class, because it has our class name prefix if (className.equals(getClass().getName())) { continue; } // ignore JFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); if (className.equals("javax.swing.JFrame") && methodName.equals("setDefaultCloseOperation")) { return; } // prevent exit() from user invoked by "designer" if (className.startsWith("org.eclipse.wb.") || className.startsWith("com.google.gdt.eclipse.designer.") || className.startsWith("net.rim.ejde.designer.") || className.startsWith("java.awt.EventQueue")) { // we often use test_exit() method as point to stop tests, allow it if (methodName.startsWith("test_") && methodName.endsWith("_exit")) { return; } // prevent exit() throw new SecurityException("Exit from within user-loaded code"); } } } } private boolean isExitVM(java.security.Permission perm) { return perm instanceof RuntimePermission && StringUtils.startsWith(perm.getName(), "exitVM"); } }); }
From source file:edu.usu.sdl.openstorefront.common.util.StringProcessor.java
/** * This will produce html highlighted stacktrace * * @param throwable//from w ww .j a va2 s .c o m * @return */ public static String parseStackTraceHtml(Throwable throwable) { StringBuilder exception = new StringBuilder(); if (throwable != null) { String message = throwable.getMessage(); if (StringUtils.isNotBlank(message)) { exception.append("<b>Message:</b> <span style='color: red;'><b>") .append(message.replace("\n", "<br>")).append("</b><br>"); } for (StackTraceElement stackTraceElement : throwable.getStackTrace()) { String style = "color: grey; font-size: 10px;"; if (stackTraceElement.getClassName().contains("edu.usu.sdl")) { style = "color: black; font-size: 12px; font-wieght: bold;"; } exception.append("<span style='").append(style).append("'>") .append(stackTraceElement.getClassName()).append(" (") .append(stackTraceElement.getMethodName()).append(") : ") .append(stackTraceElement.getLineNumber()).append(" ").append("</span><br>"); } if (throwable.getSuppressed().length > 0) { exception.append("Suppress Exceptions: "); for (Throwable suppressed : throwable.getSuppressed()) { exception.append(parseStackTraceHtml(suppressed)).append("<br>"); } } if (throwable.getCause() != null) { } } return exception.toString(); }
From source file:play.modules.pdf.PDF.java
/** * Render a specific template// www . j av a 2 s .co m * * @param templateName The template name * @param args The template data */ public static void renderTemplateAsPDF(OutputStream out, MultiPDFDocuments docs, Object... args) { Scope.RenderArgs templateBinding = Scope.RenderArgs.current(); try { // play <= v1.2.3 Class<?> clazz = Class .forName("play.classloading.enhancers.LocalvariablesNamesEnhancer.LocalVariablesNamesTracer"); Method method = clazz.getMethod("getAllLocalVariableNames", Object.class); for (Object o : args) { List<String> names = (List<String>) method.invoke(null, o); for (String name : names) { templateBinding.put(name, o); } } } catch (ClassNotFoundException e) { // play <= v1.2.3 String[] names = LVEnhancerRuntime.getParamNames().varargs; if (args != null && args.length > 0 && names == null) throw new UnexpectedException("no varargs names while args.length > 0 !"); for (int i = 0; i < args.length; i++) { templateBinding.put(names[i], args[i]); } } catch (Exception e) { throw new UnexpectedException(e); } templateBinding.put("session", Scope.Session.current()); templateBinding.put("request", Http.Request.current()); templateBinding.put("flash", Scope.Flash.current()); templateBinding.put("params", Scope.Params.current()); try { templateBinding.put("errors", Validation.errors()); } catch (Exception ex) { throw new UnexpectedException(ex); } try { if (out == null) { // we're rendering to the current Response object throw new RenderPDFTemplate(docs, templateBinding.data); } else { RenderPDFTemplate renderer = new RenderPDFTemplate(docs, templateBinding.data); renderer.writePDF(out, Http.Request.current(), Http.Response.current()); } } catch (TemplateNotFoundException ex) { if (ex.isSourceAvailable()) { throw ex; } StackTraceElement element = PlayException.getInterestingStrackTraceElement(ex); if (element != null) { throw new TemplateNotFoundException(ex.getPath(), Play.classes.getApplicationClass(element.getClassName()), element.getLineNumber()); } else { throw ex; } } }
From source file:com.googlecode.fightinglayoutbugs.helpers.TestHelper.java
private static File findSourceFileFor(StackTraceElement stackTraceElement) { final String className = stackTraceElement.getClassName(); final int i = className.lastIndexOf('.'); final String packageDir = (i == -1 ? "" : "/" + className.substring(0, i).replace('.', '/')); final File workDir = new File(new File("dummy").getAbsolutePath()).getParentFile(); // Maven 2 directory layout ... final String testSourcesDir = "src/test/java"; final String sourceFileName = stackTraceElement.getFileName(); File sourceFile = new File(testSourcesDir + packageDir, sourceFileName); if (!sourceFile.exists()) { System.err.println("Could not find " + sourceFile.getAbsolutePath() + " (current work dir: " + workDir.getAbsolutePath() + ")."); sourceFile = null;/*from ww w . j a v a2s . c om*/ } return sourceFile; }
From source file:org.seedstack.seed.core.utils.SeedReflectionUtils.java
/** * Find the caller of a method.//from w w w . ja v a 2 s . co m * * @param self the instance within the check is made. * @return the found StackTraceElement or null if not found. */ public static StackTraceElement findCaller(Object self) { StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace(); for (StackTraceElement stackTraceElement : stackTrace) { if (!stackTraceElement.getClassName().equals(Thread.class.getCanonicalName()) && !stackTraceElement.getClassName().equals(SeedReflectionUtils.class.getCanonicalName()) && !stackTraceElement.getClassName().equals(self.getClass().getCanonicalName())) { return stackTraceElement; } } return null; }
From source file:AIR.Common.DB.AbstractDLL.java
private static void logQuery(String query) { _logger.info("Query : " + query); if (_logger.isDebugEnabled()) { try {/*ww w . ja v a 2 s . com*/ StringBuilder traceBackMessage = new StringBuilder("Query traceback:\r\n"); StackTraceElement[] trace = Thread.currentThread().getStackTrace(); for (int i = 2; i < 9 && i < trace.length; i++) { StackTraceElement t = trace[i]; traceBackMessage.append(String.format(" %s.%s (%d)\r\n", t.getClassName(), t.getMethodName(), t.getLineNumber())); } _logger.debug(traceBackMessage.toString()); } catch (Throwable t) { // Ignore!! } } }
From source file:org.mule.config.ExceptionHelper.java
/** * Removes some internal Mule entries from the stacktrace. Modifies the * passed-in throwable stacktrace./*from w w w.ja va2s .c om*/ */ public static Throwable sanitize(Throwable t) { if (t == null) { return null; } StackTraceElement[] trace = t.getStackTrace(); List<StackTraceElement> newTrace = new ArrayList<StackTraceElement>(); for (StackTraceElement stackTraceElement : trace) { if (!isMuleInternalClass(stackTraceElement.getClassName())) { newTrace.add(stackTraceElement); } } StackTraceElement[] clean = new StackTraceElement[newTrace.size()]; newTrace.toArray(clean); t.setStackTrace(clean); Throwable cause = t.getCause(); while (cause != null) { sanitize(cause); cause = cause.getCause(); } return t; }