How to properly Read and understand Stacktraces. A small guide

Discussion in 'Spigot Plugin Help' started by Andre_601, Jun 30, 2021.

  1. Andre_601

    Supporter

    This post aims to help people who encounter a so called "Stacktrace" and don't understand it.
    It will teach you how a Stacktrace can be read and also gives common examples of Stacktaces you will encounter on Spigot and BungeeCord.

    1) What is a Stacktrace?
    A Stacktrace to put it simple, is one way of Java to inform someone about an Error/Exception while also giving useful information to deal with the issue.

    2) Structure of a Stacktrace
    Here is an example of a common Stacktrace and its structure:

    Code (Text):
    Exception in thread "main" java.lang.NullPointerException: null
      at com.example.path.SomeMethod.causeError(SomeMethod.java:50)
    The Stacktrace has different parts or sections.
    Starting at the top do we have the Error/Exception type. In our case is it a java.lang.NullPointerException. This tells us, what kind of Exception or Error we encountered, which in our case is a NullPointerException, which, as the name suggests, "points" to a null value, which isn't allowed.

    The next section comes after the colon and is the reason. This is one of the more important parts, as it may give some detailed information about what the issue may be.
    Java developers often have the option to provide a description/reason for an exception, if they intentionally throw one.
    Unfortunately, can there be cases where no reason is given or, just like in our example, a not understandable one.

    The final section is the path, which are all the lines starting with "at".
    These are useful for the developer, as they tell them the exact source of the issue, starting at the top layer (The first method this error was caused in) and goes down deeper until it hits the root/source of where the Exception is thrown.

    Note: There are some Stacktraces, which may have a "caused by:" section giving more details on why the exception happened (What caused it).
    This is usually the case when an Exception was caught and then rethrown by a library.

    3) Common Stacktraces in Spigot
    There is a fair share of common Exceptions when managing a server, especially when it is the first time.

    While some Exceptions can be the result of bad code, is the majority often the result of not handling a plugin or the server correctly.
    From not reading changelogs or Resource pages to simply not using the jar in the right place can there be numerous reasons for the below Exceptions to appear.

    • org.bukkit.plugin.UnknownDependencyException
      This Exception is thrown, when a plugin, which has a required Dependency that isn't installed or active on the server, is loaded.
      The Exception tells you what Dependency couldn't be found.

      To fix this, download and install the mentioned plugin into your plugins folder

    • org.bukkit.plugin.InvalidDescriptionException
      This Exception indicates an issue with the plugin description, which usually refers to the plugin.yml ("Invalid plugin.yml" as a reason)
      The issue here is, that the plugin either doesn't have a plugin.yml or it is somewhat malformed or misconfigured.

      Double-check that the Jar file you downloaded is in fact a plugin and not something like an Expansion for plugins like PlaceholderAPI.
      This is a very common issue for such plugins.

    • java.lang.UnsupportedClassVersionError
      This Error appeared more recently with the 1.17 update and is a cause due to the Java 16 requirement for it.
      The error usually indicates that the plugin was compiled (build) with a more recent Version of Java, such as Java 11 or 16, while the server itself uses an older Java version (i.e. Java 8) that doesn't support this newer version.

      The easiest fix here is to just update your Java version to at least the one mentioned. Unfortunately does Java only mention the class file version, but a simple Google search should reveal what actual Java version this is.
    Don't see a common Stacktrace here?
    Tell me together with what it is about and how to fix and I'll add it.
     
    #1 Andre_601, Jun 30, 2021
    Last edited: Jun 30, 2021
    • Like Like x 2
    • Winner Winner x 1
  2. You explained it well. Good post! :)
     
  3. Great post andre! (y)

    I'm not sure this is the correct description, a stacktrace is not itself an error nor an exception. It decribes an error or an exception. Officially it's an array of stack frames - only about wording it right though.

    This is known as "cause". It's commonly used by libraries when an exception is caught and then rethrown.
     
  4. Andre_601

    Supporter

    Rephrased it a bit
     
    • Like Like x 1