This is a simple guide about reading a stack trace for beginners. We use an exception caused inside a command for example.

What is a stack trace

Stack Trace is a list of method calls from the point when the application was started to the point where the exception was thrown.


The red text in the image is a stack trace.

The stack trace is essentially the part of the error what tells what went wrong and where.

Reading the example

Let me add some markings to the image. Here.

The sample stack trace divided up in parts.

I've divided the error up in 5 parts.

The first one (yellow on the image) is a quick summary what happened. In our case, it tells us that something went wrong while executing command foo and it is in plugin Stacktrace version 1.0.0.

The second and fifth ones (red on the image) are internal calls done by Spigot. We do not have to read them.

The third part (green on the image) is the original exception. In this case, it is a java.lang.ArrayIndexOutOfBoundsException with description 0.

Lastly, the fourth part (blue on the image) tells us where this error occurred. The first call in this part happened last. In our case, it says that the error was caused in class me.tassu.stacktrace.FooCommand, method doMoreStuff, line 22.

Now we can look at our code and take a look at line 22 in FooCommand.

As we could guess, on line 22 the code tries to access the first element on args (arrays start at index 0) without checking the length first. There is a simple fix:

We added a simple if statement checking for the length of the array, and if the array is empty we tell the user that we need an argument. Problem solved!