Skip to main content

Reading Stacktraces

What is a stacktrace?

In Java, a stacktrace shows the call stack of a thread. The call stack is the path of execution that led to the current point in the program. Usually, the stacktrace will be printed to the console when an exception is not handled correctly.

Stacktraces are a useful tool for debugging your code. They show you the exact line of code that caused an error, and the line of code that called that line of code, and so on. This is useful because it allows you to see the exact path of execution that led to the error.


Here is an example of a stacktrace which has been caused due to a NullPointerException:

[15:20:42 ERROR]: Could not pass event PluginEnableEvent to TestPlugin v1.0
java.lang.NullPointerException: Cannot invoke "Object.toString()" because "player" is null
at io.papermc.testplugin.TestPlugin.onPluginEnable( ~[TestPlugin-1.0-SNAPSHOT.jar:?]
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor1.execute(Unknown Source) ~[?:?]
at org.bukkit.plugin.EventExecutor$2.execute( ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
at co.aikar.timings.TimedEventExecutor.execute( ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:git-Paper-49]
at org.bukkit.plugin.RegisteredListener.callEvent( ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.plugin.manager.PaperEventManager.callEvent( ~[paper-1.20.2.jar:git-Paper-49]
at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent( ~[paper-1.20.2.jar:git-Paper-49]
at org.bukkit.plugin.SimplePluginManager.callEvent( ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin( ~[paper-1.20.2.jar:git-Paper-49]
at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin( ~[paper-1.20.2.jar:git-Paper-49]
at org.bukkit.plugin.SimplePluginManager.enablePlugin( ~[paper-api-1.20.2-R0.1-SNAPSHOT.jar:?]
at org.bukkit.craftbukkit.v1_20_R2.CraftServer.enablePlugin( ~[paper-1.20.2.jar:git-Paper-49]
at org.bukkit.craftbukkit.v1_20_R2.CraftServer.enablePlugins( ~[paper-1.20.2.jar:git-Paper-49]
at net.minecraft.server.MinecraftServer.loadWorld0( ~[paper-1.20.2.jar:git-Paper-49]
at net.minecraft.server.MinecraftServer.loadLevel( ~[paper-1.20.2.jar:git-Paper-49]
at net.minecraft.server.dedicated.DedicatedServer.initServer( ~[paper-1.20.2.jar:git-Paper-49]
at net.minecraft.server.MinecraftServer.runServer( ~[paper-1.20.2.jar:git-Paper-49]
at net.minecraft.server.MinecraftServer.lambda$spin$0( ~[paper-1.20.2.jar:git-Paper-49]
at ~[?:?]
  • Firstly, we can see that this certain error occurred when the PluginEnableEvent was being handled by the TestPlugin.

  • Then we can see on the second line, the cause of the exception:

    java.lang.NullPointerException: Cannot invoke "Object.toString()" because "player" is null

    This tells us that the exception was caused by a NullPointerException, and that the exception was caused because we tried to call the toString() method on a null "player" object.

  • From here, as we work down the stacktrace, we can see the exact path of execution that led to the error. In this case, the next line of the stacktrace is:

    at io.papermc.testplugin.TestPlugin.onPluginEnable( ~[TestPlugin-1.0-SNAPSHOT.jar:?]

    Which tells us that the error was thrown at line 23 of

  • You can continue to work down the stacktrace, and see the exact path of execution that led to the error. In this case, it is server internals, so we can generally ignore it.

Omitted Stacktraces

In JDK 5, the JVM started to omit stacktraces for certain exceptions. This was common when the JVM had optimised the code, and you could get NullPointerExceptions without a stacktrace. In order to fix this, you can pass the -XX:-OmitStackTraceInFastThrow flag to the JVM:

java -XX:-OmitStackTraceInFastThrow -jar paper.jar