mojira.dev
MC-307905

Crash report generation can crash when `StackTraceElement.getFileName()` is null

Minecraft's crash report generation can throw a secondary NullPointerException when validating a stack trace.

The problem is in CrashReportCategory.validateStackTrace. The method compares stack trace file names with:

current.getFileName().equals(source.getFileName())

However, StackTraceElement.getFileName() may return null. If current.getFileName() is null, crash report generation itself crashes with:

[11:49:53] [Render thread] [FabricLoader/ERROR]: Uncaught exception in thread "Render thread"
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "java.lang.StackTraceElement.getFileName()" is null
	at knot//net.minecraft.CrashReportCategory.validateStackTrace(CrashReportCategory.java:127)
	at knot//net.minecraft.CrashReport.addCategory(CrashReport.java:201)
	at knot//net.minecraft.CrashReport.addCategory(CrashReport.java:176)
	at java.base/java.lang.Thread.run(Unknown Source)

This can hide the original crash and prevent Minecraft from producing a proper crash report.

Suggested fix:

Use a null-safe comparison for the file name:

Objects.equals(current.getFileName(), source.getFileName())

instead of:

current.getFileName().equals(source.getFileName())


Patch:

-            if (current.isNativeMethod() == source.isNativeMethod() && current.getClassName().equals(source.getClassName()) && current.getFileName().equals(source.getFileName()) && current.getMethodName().equals(source.getMethodName())) {
+            if (current.isNativeMethod() == source.isNativeMethod() && current.getClassName().equals(source.getClassName()) && Objects.equals(current.getFileName(), source.getFileName()) && current.getMethodName().equals(source.getMethodName())) {

Comments 2

Hi!
Thank you for your report!Β 

  • Can you reproduce this issue in vanilla environment? Logs indicate that you are using a modded version of the game.

  • If yes, can you also provide reproduction steps if there are any?

Quick Links:Β 
πŸ““β€―Issue Guidelines – πŸ’¬β€―Mojang Support – πŸ“§β€―Suggestions – πŸ“–β€―Minecraft Wiki

The issue is random for some users.
I was asked by Fabulously Optimized modpack author to find reason of this.

According to Java documentation StackTraceElement.getFileName() can return null.

Returns: the name of the file containing the execution point represented by this stack trace element, or null if this information is unavailable.

You are calling getFileName().equals unsafe way without null check, so it’s causing issues.

KostromDan

boq

Plausible

Platform HC

Important

Crash

26.1.2

26.2 Snapshot 7

Retrieved