{"id":17864,"date":"2018-04-30T08:54:52","date_gmt":"2018-04-30T13:54:52","guid":{"rendered":"https:\/\/stackify.com\/?p=17864"},"modified":"2024-05-31T04:32:35","modified_gmt":"2024-05-31T04:32:35","slug":"java-stack-trace","status":"publish","type":"post","link":"https:\/\/stackify.com\/java-stack-trace\/","title":{"rendered":"Understanding and Leveraging the Java Stack Trace"},"content":{"rendered":"<p>Stack traces are probably one of the most common things you&#8217;re regularly running into while working as a Java developer. When <a href=\"https:\/\/stackify.com\/best-practices-exceptions-java\/\" target=\"_blank\" rel=\"noopener noreferrer\">unhandled exceptions<\/a> are thrown, stack traces are simply printed to the console by default.<\/p>\n<p>Nevertheless, it&#8217;s easy to only have a surface-level understanding of what these are and how to use them. This article will shed light on the subject.<\/p>\n<h2>What is a Stack Trace?<\/h2>\n<p>Simply put, a stack trace is a representation of a call stack at a certain point in time, with each element representing a method invocation. The stack trace contains all invocations from the start of a thread until the point it&#8217;s generated. This is usually a position at which an exception takes place.<\/p>\n<p>A stack trace&#8217;s textual form like this should look familiar:<\/p>\n<pre class=\"prettyprint\">Exception in thread \"main\" java.lang.RuntimeException: A test exception\n  at com.stackify.stacktrace.StackTraceExample.methodB(StackTraceExample.java:13)\n  at com.stackify.stacktrace.StackTraceExample.methodA(StackTraceExample.java:9)\n  at com.stackify.stacktrace.StackTraceExample.main(StackTraceExample.java:5)<\/pre>\n<p>When printed out, the generation point shows up first, and method invocations leading to that point are displayed underneath. This printing order makes sense because when an exception occurs, you want to look at the most recent methods first. These methods are likely to contain the root cause of the failure rather than those far away.<\/p>\n<p>The rest of this article will take an in-depth look at stack traces, starting with the <em>StackTraceElement<\/em> class. Each instance of this class indicates an element in a stack trace.<\/p>\n<p>The Stack Walking API, introduced in Java 9 to provide a more flexible mechanism to traverse call stacks, will be covered as well.<\/p>\n<h3><strong>The <em>StackTraceElement<\/em> Class<\/strong><\/h3>\n<p><strong>A stack trace consists of stack trace elements.<\/strong> Before Java 9, the only way to denote such elements is to use the <em>StackTraceElement<\/em> class.<\/p>\n<h4>Accessible Information<\/h4>\n<p>A <em>StackTraceElement<\/em> object provides you with access to basic data on a method invocation, including the names of the class and method where that invocation occurs. You can retrieve this info using these straightforward APIs:<\/p>\n<ul>\n<li><em>getClassName<\/em> &#8211; returns the fully qualified name of the class containing the method invocation<\/li>\n<li><em>getMethodName<\/em> &#8211; returns the name of the method containing the method invocation<\/li>\n<\/ul>\n<p>Starting with Java 9, you can also obtain data on the containing module of a stack frame &#8211; using the <em>getModuleName<\/em> and <em>getModuleVersion<\/em> methods.<\/p>\n<p>Thanks to the <a href=\"https:\/\/docs.oracle.com\/javase\/specs\/jvms\/se10\/html\/jvms-4.html#jvms-4.7.10\" rel=\"noopener\"><em>SourceFile<\/em><\/a> and <a href=\"https:\/\/docs.oracle.com\/javase\/specs\/jvms\/se10\/html\/jvms-4.html#jvms-4.7.12\" rel=\"noopener\"><em>LineNumberTable<\/em><\/a> attributes in the class file, the corresponding position of a frame in the source file is identifiable as well. This information is very helpful for debugging purposes:<\/p>\n<ul>\n<li><em>getFileName<\/em> &#8211; returns the name of the source file associated with the class containing the method invocation<\/li>\n<li><em>getLineNumber<\/em> &#8211; returns the line number of the source line containing the execution point<\/li>\n<\/ul>\n<p>For a complete list of methods in the <em>StackTraceElement<\/em> class, see <a href=\"https:\/\/docs.oracle.com\/javase\/10\/docs\/api\/java\/lang\/StackTraceElement.html\" rel=\"noopener\">the Java API documentation<\/a>.<\/p>\n<p>Before moving on to a couple of methods that you can use to obtain elements of a stack trace, take a look at the skeleton of a simple example class:<\/p>\n<pre class=\"prettyprint\">package com.stackify.stacktrace;\n\npublic class StackElementExample {\n    \/\/ example methods go here\n}<\/pre>\n<p>This class will contain methods illustrating a stack trace.<\/p>\n<p>The following test class will be filled with methods calling those in the <em>StackElementExample<\/em> class:<\/p>\n<pre class=\"prettyprint\">package com.stackify.stacktrace;\n\n\/\/ import statements\n\npublic class StackElementExampleTest {\n    \/\/ test methods go here\n}<\/pre>\n<h4>Accessing Stack Traces with the <em>Thread <\/em>Class<\/h4>\n<p>You can obtain a stack trace from <a href=\"https:\/\/stackify.com\/java-thread-pools\/\">a thread<\/a> &#8211; by calling the <em>getStackTrace<\/em> method on that <em>Thread<\/em> instance. This invocation returns an array of <em>StackTraceElement<\/em>, from which details about stack frames of the thread can be extracted.<\/p>\n<p>The following are two methods of the <em>StackElementExample<\/em> class. One of them calls the other, hence both become part of the same call stack:<\/p>\n<pre class=\"prettyprint\">public StackTraceElement[] methodA() {\n    return methodB();\n}\n\npublic StackTraceElement[] methodB() {\n    Thread thread = Thread.currentThread();\n    return thread.getStackTrace();\n}<\/pre>\n<p>The first element in the stack trace created in <em>methodB<\/em> is the invocation of the <em>getStackTrace<\/em> method itself. The second element, at index <em>1<\/em>, is the method enclosing that invocation.<\/p>\n<p>Here&#8217;s a quick test that verifies the class and method names:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenElementOneIsReadUsingThread_thenMethodUnderTestIsObtained() {\n    StackTraceElement[] stackTrace = new StackElementExample().methodA();\n    StackTraceElement elementOne = stackTrace[1];\n    assertEquals(\"com.stackify.stacktrace.StackElementExample\", elementOne.getClassName());\n    assertEquals(\"methodB\", elementOne.getMethodName());\n}<\/pre>\n<p>When a test method calls <em>methodA<\/em> in the example class, which in turn calls <em>methodB<\/em>, that test method should be two elements away from <em>methodB<\/em> in the stack:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenElementThreeIsReadUsingThread_thenTestMethodIsObtained() {\n    StackTraceElement[] stackTrace = new StackElementExample().methodA();\n    StackTraceElement elementThree = stackTrace[3];\n    assertEquals(\"com.stackify.stacktrace.StackElementExampleTest\", elementThree.getClassName());\n    assertEquals(\"whenElementThreeIsReadUsingThread_thenTestMethodIsObtained\", elementThree.getMethodName());\n}<\/pre>\n<h4>Accessing Stack Traces with the <em>Throwable <\/em>Class<\/h4>\n<p>When the program throws a <em>Throwable<\/em> instance, instead of simply printing the stack trace on the console or logging it, you can obtain an array of <em>StackTraceElement<\/em> objects by calling the <em>getStackTrace<\/em> method on that instance. The signature and the return value of this method are the same as those of the method in the <em>Thread<\/em> class you have gone through.<\/p>\n<p>Here are two methods featuring the throwing and handling of a <em>Throwable<\/em> object:<\/p>\n<pre class=\"prettyprint\">public StackTraceElement[] methodC() {\n    try {\n        methodD();\n    } catch (Throwable t) {\n        return t.getStackTrace();\n    }\n    return null;\n}\n\npublic void methodD() throws Throwable {\n    throw new Throwable(\"A test exception\");\n}<\/pre>\n<p>When the <em>Throwable<\/em> is thrown, a stack trace is generated at the point where the problem occurs. As a result, the first element of the stack is the method containing the throwing:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenElementZeroIsReadUsingThrowable_thenMethodThrowingThrowableIsObtained() {\n    StackTraceElement[] stackTrace = new StackElementExample().methodC();\n    StackTraceElement elementZero = stackTrace[0];\n    assertEquals(\"com.stackify.stacktrace.StackElementExample\", elementZero.getClassName());\n    assertEquals(\"methodD\", elementZero.getMethodName());\n}<\/pre>\n<p>And the second is the method that <a href=\"https:\/\/stackify.com\/specify-handle-exceptions-java\/\">handles<\/a> the <em>Throwable<\/em>:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenElementOneIsReadUsingThrowable_thenMethodCatchingThrowableIsObtained() {\n    StackTraceElement[] stackTrace = new StackElementExample().methodC();\n    StackTraceElement elementOne = stackTrace[1];\n    assertEquals(\"com.stackify.stacktrace.StackElementExample\", elementOne.getClassName());\n    assertEquals(\"methodC\", elementOne.getMethodName());\n}<\/pre>\n<p>If you were to change the body of the <em>catch<\/em> block in <em>methodC<\/em> to a trivial handling:<\/p>\n<pre class=\"prettyprint\">t.printStackTrace();<\/pre>\n<p>you would see the textual representation of the stack trace:<\/p>\n<pre class=\"prettyprint\">java.lang.Throwable: A test exception\n  at com.stackify.stacktrace.StackElementExample.methodD(StackElementExample.java:23)\n  at com.stackify.stacktrace.StackElementExample.methodC(StackElementExample.java:15)\n  at com.stackify.stacktrace.StackElementExampleTest\n    .whenElementOneIsReadUsingThrowable_thenMethodCatchingThrowableIsObtained(StackElementExampleTest.java:34)\n...<\/pre>\n<p>As you can see, the text output reflects the <em>StackTraceElement<\/em> array.<\/p>\n<h3><strong>The Stack Walking API<\/strong><\/h3>\n<p>One of the prominent features of Java 9 is the Stack Walking API. This section will go over the driving forces behind the introduction of this API, and how to use it to traverse stack traces.<\/p>\n<h4>Drawbacks of <em>StackStraceElement<\/em><\/h4>\n<p>A <em>StackTraceElement<\/em> object provides more information than a single line in the textual representation of a stack trace. However, each piece of data &#8211; such an object stores &#8211; is still in a simple form: a <em>String<\/em> or a primitive value; it doesn&#8217;t reference a <em>Class<\/em> object. Consequently, it&#8217;s not easy to use information from a stack trace in the program.<\/p>\n<p>Another problem with the old way of retrieving stack traces is that you cannot ignore frames that you don&#8217;t need. On the other hand, you may lose useful elements as the <a href=\"https:\/\/stackify.com\/jvm-metrics\/\">JVM<\/a> may skip some frames for the performance. In the end, it&#8217;s possible to have elements you don&#8217;t want and don&#8217;t have some you actually need.<\/p>\n<h4>The Stack Walking API to the Rescue<\/h4>\n<p>The Stack Walking API provides a flexible mechanism to traverse and extract information from call stacks, allowing you to filter, then access frames, in a lazy manner. This API works around <a href=\"https:\/\/docs.oracle.com\/javase\/10\/docs\/api\/java\/lang\/StackWalker.html\" rel=\"noopener\">the <em>StackWalker<\/em> class<\/a>, which encloses two inner types: <em>StackFrame<\/em> and <em>Option<\/em>.<\/p>\n<h4>Stack Frames<\/h4>\n<p>An instance of <a href=\"https:\/\/docs.oracle.com\/javase\/10\/docs\/api\/java\/lang\/StackWalker.StackFrame.html\" rel=\"noopener\">the <em>StackFrame<\/em> interface<\/a> represents an individual frame in a stack, much like what a <em>StackTraceElement<\/em> object does. As you&#8217;d expect, this interface defines a number of APIs, similar to those in the <em>StackTraceElement<\/em> class, e.g. <em>getMethodName<\/em> or <em>getLineNumber<\/em>.<\/p>\n<p>And, if you need to, you can convert a <em>StackFrame<\/em> object to <em>StackTraceElement<\/em> by calling the method <em>toStackTraceElement<\/em>.<\/p>\n<p>However, there is an important API that makes <em>StackFrame<\/em> a better choice than <em>StackTraceElement &#8211; <\/em>namely <em>getDeclaringClass<\/em>. This method returns a <em>Class<\/em> instance, enabling you to perform more complex operations than what you could do with a simple class name. However, do note this is only applicable if the stack walker is set up to retain <em>Class<\/em> objects.<\/p>\n<p>The next subsection will go over the options you can set for such a stack walker.<\/p>\n<h4>Stack Walker Options<\/h4>\n<p>Instances of <a href=\"https:\/\/docs.oracle.com\/javase\/10\/docs\/api\/java\/lang\/StackWalker.Option.html\" rel=\"noopener\">the <em>Option<\/em> enum type<\/a> can be used to determine the information retrieved by a stack walker.<\/p>\n<p>Here&#8217;s a complete list of its constants:<\/p>\n<ul>\n<li><em>RETAIN_CLASS_REFERENCE<\/em> &#8211; retains the <em>Class<\/em> object in each stack frame during a stack walk<\/li>\n<li><em>SHOW_REFLECT_FRAMES<\/em> &#8211; shows all reflection frames<\/li>\n<li><em>SHOW_HIDDEN_FRAMES <\/em>&#8211; shows all hidden frames, including reflection frames<\/li>\n<\/ul>\n<h4>The <em>StackWalker<\/em> Class<\/h4>\n<p>The <em>StackWalker<\/em> class is the entry point to the Stack Walking API. This class doesn&#8217;t define public constructors; you must use one of the overloading static methods, named <em>getInstance<\/em>, to create its objects.<\/p>\n<p>You can have a <em>StackWalker<\/em> with the default configuration by calling <em>getInstance<\/em> with no arguments. This configuration instructs the stack walker to retain no class references and omit all hidden frames.<\/p>\n<p>You can also pass an <em>Option<\/em> constant to that method. In case multiple options are provided, they must be wrapped in a <em>Set<\/em> before being used to construct a stack walker.<\/p>\n<p><strong>The most noticeable method of <em>StackWalker<\/em> is the <em>walk<\/em> method.<\/strong> This method applies a <em>Function<\/em> to the stream of <em>StackFrame<\/em> objects, starting from the top frame where the invocation of the <em>walk<\/em> method occurs.<\/p>\n<p>The frame stream is closed when the <em>walk<\/em> method returns, and it does so for good reason. Since the JVM is free to reorganize the stack for the performance, the result would be inaccurate if you accessed the stream after the <em>walk<\/em> method completed.<\/p>\n<p>You can also use a derivative of the <em>walk<\/em> method, namely <em>forEach<\/em>. This method performs a <em>Consumer<\/em> on elements of the <em>StackFrame<\/em> stream.<\/p>\n<p><strong>Notice that the <em>StackWalker <\/em>class is thread-safe<\/strong>. Multiple threads can share a single <em>StackWalker<\/em> instance to go through their own stack without causing any concurrency issues.<\/p>\n<p>To illustrate the Stack Walking API, let&#8217;s have a look at this simple class:<\/p>\n<pre class=\"prettyprint\">package com.stackify.stacktrace;\n\npublic class StackWalkingExample {\n    \/\/ example methods go here\n}<\/pre>\n<p>And this test class:<\/p>\n<pre class=\"prettyprint\">package com.stackify.stacktrace;\n\n\/\/ import statements\n\npublic class StackWalkingExampleTest {\n    \/\/ test methods go here\n}<\/pre>\n<h4>Stack Walking with No Options<\/h4>\n<p>Let&#8217;s start with a no-option <em>StackWalker<\/em>. This walker will walk through the call stack, retaining only frames of its interest and returning them as a list:<\/p>\n<pre class=\"prettyprint\">public List&lt;StackFrame&gt; walkWithNoOptions() {\n    StackWalker walker = StackWalker.getInstance();\n    return walker.walk(s -&gt; s.filter(f -&gt; f.getClassName().startsWith(\"com.stackify\")).collect(Collectors.toList()));\n}<\/pre>\n<p>The returned list consists of frames corresponding to methods whose class has a qualified name starting with <em>com.stackify<\/em>. This list has two elements, one denotes the method under test, and the other indicates the test method itself.<\/p>\n<p>Here&#8217;s a test verifying that:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenWalkWithNoOptions_thenFramesAreReturned() {\n    List&lt;StackFrame&gt; frames = new StackWalkingExample().walkWithNoOptions();\n    assertEquals(2, frames.size());\n}<\/pre>\n<p>You can also go through the stack and perform a given action on each frame using the <em>forEach<\/em> method. You cannot filter or limit the number of extracted frames with this method, though.<\/p>\n<p>The following method returns a list of all the frames captured in a stack:<\/p>\n<pre class=\"prettyprint\">public List&lt;StackFrame&gt; forEachWithNoOptions() {\n    List&lt;StackFrame&gt; frames = new ArrayList&lt;&gt;();\n    StackWalker walker = StackWalker.getInstance(Collections.emptySet());\n    walker.forEach(frames::add);\n    return frames;\n}<\/pre>\n<p>The empty <em>Set<\/em> argument to the <em>getInstance<\/em> method is used just to make it clear that you can pass a set of options when creating a <em>StackWalker<\/em>. It doesn&#8217;t have any other meaning here.<\/p>\n<p>This test checks the state of the returned frames:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenForEachWithNoOptions_thenFramesAreReturned() {\n    List&lt;StackFrame&gt; frames = new StackWalkingExample().forEachWithNoOptions();\n    StackFrame topFrame = frames.get(0);\n    assertEquals(\"com.stackify.stacktrace.StackWalkingExample\", topFrame.getClassName());\n    assertEquals(\"forEachWithNoOptions\", topFrame.getMethodName());\n    assertEquals(0, frames.stream().filter(f -&gt; f.getClassName().equals(\"java.lang.reflect.Method\")).count());\n}<\/pre>\n<p>Notice the last assertion, which confirms that the stack walk didn&#8217;t keep reflection frames. You must specify an appropriate option to make those frames show up.<\/p>\n<h4>Using the <em>RETAIN_CLASS_REFERENCE <\/em>Option<\/h4>\n<p>Let&#8217;s now have a look at a <em>StackWalker<\/em> with the <em>RETAIN_CLASS_REFERENCE<\/em> option:<\/p>\n<pre class=\"prettyprint\">public StackFrame walkWithRetainClassReference() {\n    StackWalker walker = StackWalker.getInstance(RETAIN_CLASS_REFERENCE);\n    return walker.walk(s -&gt; s.findFirst().get());\n}<\/pre>\n<p>The <em>walk<\/em> method, in this case, returns the top frame of the stack. This frame represents the method calling the <em>walk<\/em> method itself.<\/p>\n<p>Let&#8217;s create a simple test to confirm that:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenWalkWithRetainClassReference_thenAFrameIsReturned() {\n    StackFrame topFrame = new StackWalkingExample().walkWithRetainClassReference();\n    assertEquals(StackWalkingExample.class, topFrame.getDeclaringClass());\n    assertEquals(\"walkWithRetainClassReference\", topFrame.getMethodName());\n}<\/pre>\n<p>The <em>getDeclaringClass<\/em> method works due to the setting of the <em>RETAIN_CLASS_REFERENCE<\/em> option.<\/p>\n<h4>Using the <em>SHOW_REFLECT_FRAMES <\/em>Option<\/h4>\n<p>Next, let&#8217;s look at a method that configures a <em>StackWalker<\/em> with the <em>SHOW_REFLECT_FRAMES<\/em> option:<\/p>\n<pre class=\"prettyprint\">public List&lt;StackFrame&gt; walkWithShowReflectFrames() {\n    StackWalker walker = StackWalker.getInstance(SHOW_REFLECT_FRAMES);\n    return walker.walk(s -&gt; s.collect(Collectors.toList()));\n}<\/pre>\n<p>Here&#8217;s a quick test which verifies the existence of reflection frames in the stack trace:<\/p>\n<pre class=\"prettyprint\">@Test\npublic void whenWalkWithShowReflectFrames_thenFramesAreReturned() {\n    List&lt;StackFrame&gt; frames = new StackWalkingExample().walkWithShowReflectFrames();\n    assertNotEquals(0, frames.stream().filter(f -&gt; f.getClassName().equals(\"java.lang.reflect.Method\")).count());\n}<\/pre>\n<p>The last option, <em>SHOW_HIDDEN_FRAMES<\/em>, can be used to show all hidden frames, including reflection frames. For instance, lambda expressions only show up in the stack trace when applying this option.<\/p>\n<h3><strong>Summary<\/strong><\/h3>\n<p>Java gives us many interesting ways to get access to a stack trace; and, starting with Java 9, the natural option is the Stack Walking API.<\/p>\n<p>This is, simply put, significantly more powerful than the older APIs and can lead to highly useful&nbsp;debugging tools, allowing you to capture the call stack at any particular point in time, and get to the root of any problem quickly.<\/p>\n<p>With APM, server health metrics, and error log integration, improve the performance of your Java apps with Stackify Retrace.&nbsp; <a href=\"https:\/\/s1.stackify.com\/account\/createclient?_ga=2.57834090.1973545731.1588002198-1971815645.1570122931&amp;_gac=1.238281396.1584390051.EAIaIQobChMIvenD6Oif6AIVnP7jBx3XjACyEAAYBCAAEgJmVPD_BwE\">Try your free two week trial today<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stack traces are probably one of the most common things you&#8217;re regularly running into while working as a Java developer. When unhandled exceptions are thrown, stack traces are simply printed to the console by default. Nevertheless, it&#8217;s easy to only have a surface-level understanding of what these are and how to use them. This article [&hellip;]<\/p>\n","protected":false},"author":15,"featured_media":37772,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7],"tags":[40],"class_list":["post-17864","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v25.6) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Understanding and Leveraging the Java Stack Trace- Stackify<\/title>\n<meta name=\"description\" content=\"Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root cause.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/stackify.com\/java-stack-trace\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Understanding and Leveraging the Java Stack Trace- Stackify\" \/>\n<meta property=\"og:description\" content=\"Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root cause.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/stackify.com\/java-stack-trace\/\" \/>\n<meta property=\"og:site_name\" content=\"Stackify\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Stackify\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-30T13:54:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-05-31T04:32:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"881\" \/>\n\t<meta property=\"og:image:height\" content=\"441\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Eugen Paraschiv\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@stackify\" \/>\n<meta name=\"twitter:site\" content=\"@stackify\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eugen Paraschiv\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/\"},\"author\":{\"name\":\"Eugen Paraschiv\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/person\/e372b6a6f64edbedafad33027d518482\"},\"headline\":\"Understanding and Leveraging the Java Stack Trace\",\"datePublished\":\"2018-04-30T13:54:52+00:00\",\"dateModified\":\"2024-05-31T04:32:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/\"},\"wordCount\":1857,\"publisher\":{\"@id\":\"https:\/\/stackify.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg\",\"keywords\":[\"Java\"],\"articleSection\":[\"Developer Tips, Tricks &amp; Resources\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/\",\"url\":\"https:\/\/stackify.com\/java-stack-trace\/\",\"name\":\"Understanding and Leveraging the Java Stack Trace- Stackify\",\"isPartOf\":{\"@id\":\"https:\/\/stackify.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg\",\"datePublished\":\"2018-04-30T13:54:52+00:00\",\"dateModified\":\"2024-05-31T04:32:35+00:00\",\"description\":\"Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root cause.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/stackify.com\/java-stack-trace\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/stackify.com\/java-stack-trace\/#primaryimage\",\"url\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg\",\"contentUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg\",\"width\":881,\"height\":441},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/stackify.com\/#website\",\"url\":\"https:\/\/stackify.com\/\",\"name\":\"Stackify\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/stackify.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/stackify.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/stackify.com\/#organization\",\"name\":\"Stackify\",\"url\":\"https:\/\/stackify.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png\",\"contentUrl\":\"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png\",\"width\":1377,\"height\":430,\"caption\":\"Stackify\"},\"image\":{\"@id\":\"https:\/\/stackify.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Stackify\/\",\"https:\/\/x.com\/stackify\",\"https:\/\/www.instagram.com\/stackify\/\",\"https:\/\/www.linkedin.com\/company\/2596184\",\"https:\/\/www.youtube.com\/stackify\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/person\/e372b6a6f64edbedafad33027d518482\",\"name\":\"Eugen Paraschiv\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/stackify.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0c0bb39bd24aea78b56c6516a3e7dcab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0c0bb39bd24aea78b56c6516a3e7dcab?s=96&d=mm&r=g\",\"caption\":\"Eugen Paraschiv\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Understanding and Leveraging the Java Stack Trace- Stackify","description":"Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root cause.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/stackify.com\/java-stack-trace\/","og_locale":"en_US","og_type":"article","og_title":"Understanding and Leveraging the Java Stack Trace- Stackify","og_description":"Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root cause.","og_url":"https:\/\/stackify.com\/java-stack-trace\/","og_site_name":"Stackify","article_publisher":"https:\/\/www.facebook.com\/Stackify\/","article_published_time":"2018-04-30T13:54:52+00:00","article_modified_time":"2024-05-31T04:32:35+00:00","og_image":[{"width":881,"height":441,"url":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg","type":"image\/jpeg"}],"author":"Eugen Paraschiv","twitter_card":"summary_large_image","twitter_creator":"@stackify","twitter_site":"@stackify","twitter_misc":{"Written by":"Eugen Paraschiv","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/stackify.com\/java-stack-trace\/#article","isPartOf":{"@id":"https:\/\/stackify.com\/java-stack-trace\/"},"author":{"name":"Eugen Paraschiv","@id":"https:\/\/stackify.com\/#\/schema\/person\/e372b6a6f64edbedafad33027d518482"},"headline":"Understanding and Leveraging the Java Stack Trace","datePublished":"2018-04-30T13:54:52+00:00","dateModified":"2024-05-31T04:32:35+00:00","mainEntityOfPage":{"@id":"https:\/\/stackify.com\/java-stack-trace\/"},"wordCount":1857,"publisher":{"@id":"https:\/\/stackify.com\/#organization"},"image":{"@id":"https:\/\/stackify.com\/java-stack-trace\/#primaryimage"},"thumbnailUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg","keywords":["Java"],"articleSection":["Developer Tips, Tricks &amp; Resources"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/stackify.com\/java-stack-trace\/","url":"https:\/\/stackify.com\/java-stack-trace\/","name":"Understanding and Leveraging the Java Stack Trace- Stackify","isPartOf":{"@id":"https:\/\/stackify.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/stackify.com\/java-stack-trace\/#primaryimage"},"image":{"@id":"https:\/\/stackify.com\/java-stack-trace\/#primaryimage"},"thumbnailUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg","datePublished":"2018-04-30T13:54:52+00:00","dateModified":"2024-05-31T04:32:35+00:00","description":"Learn to understand and utilize the stack traces in Java. These are a highly powerful tool that can lead you to the root cause.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/stackify.com\/java-stack-trace\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/stackify.com\/java-stack-trace\/#primaryimage","url":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg","contentUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2018\/04\/Understanding_Java_Stack_Trace-881x441-1.jpg","width":881,"height":441},{"@type":"WebSite","@id":"https:\/\/stackify.com\/#website","url":"https:\/\/stackify.com\/","name":"Stackify","description":"","publisher":{"@id":"https:\/\/stackify.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/stackify.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/stackify.com\/#organization","name":"Stackify","url":"https:\/\/stackify.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/stackify.com\/#\/schema\/logo\/image\/","url":"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png","contentUrl":"https:\/\/stackify.com\/wp-content\/uploads\/2024\/05\/logo-1.png","width":1377,"height":430,"caption":"Stackify"},"image":{"@id":"https:\/\/stackify.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Stackify\/","https:\/\/x.com\/stackify","https:\/\/www.instagram.com\/stackify\/","https:\/\/www.linkedin.com\/company\/2596184","https:\/\/www.youtube.com\/stackify"]},{"@type":"Person","@id":"https:\/\/stackify.com\/#\/schema\/person\/e372b6a6f64edbedafad33027d518482","name":"Eugen Paraschiv","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/stackify.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0c0bb39bd24aea78b56c6516a3e7dcab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0c0bb39bd24aea78b56c6516a3e7dcab?s=96&d=mm&r=g","caption":"Eugen Paraschiv"}}]}},"_links":{"self":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts\/17864"}],"collection":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/comments?post=17864"}],"version-history":[{"count":0,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/posts\/17864\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/media\/37772"}],"wp:attachment":[{"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/media?parent=17864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/categories?post=17864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stackify.com\/wp-json\/wp\/v2\/tags?post=17864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}