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 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.
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
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
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
Now we can look at our code and take a look at line 22 in
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!