mojira.dev
MC-230525

Dedicated server failing to bind to port causes NullPointerException

The bug

When the dedicated server fails to bind to the specified port, e.g. because another application is already using that port, a NullPointerException occurs:

1.17.1-pre1

[15:59:42] [Server thread/WARN]: **** FAILED TO BIND TO PORT!
[15:59:42] [Server thread/WARN]: The exception was: java.net.BindException: Address already in use: bind
[15:59:42] [Server thread/WARN]: Perhaps a server is already running on that port?
[15:59:42] [Server thread/INFO]: Stopping server
[15:59:42] [Server thread/INFO]: Saving worlds
[15:59:42] [Server thread/ERROR]: Exception stopping the server
java.lang.NullPointerException: Cannot invoke "abr.o_()" because "Γÿâ" is null
        at net.minecraft.server.MinecraftServer.a(SourceFile:592) ~[1.17.1-pre1.jar:?]
        at net.minecraft.server.MinecraftServer.u(SourceFile:619) ~[1.17.1-pre1.jar:?]
        at aas.u(SourceFile:585) ~[1.17.1-pre1.jar:?]
        at net.minecraft.server.MinecraftServer.x(SourceFile:729) ~[1.17.1-pre1.jar:?]
        at net.minecraft.server.MinecraftServer.a(SourceFile:274) ~[1.17.1-pre1.jar:?]
        at java.lang.Thread.run(Thread.java:831) [?:?]

Expected would be that the server cleanly exits without any exception.

Reproduction steps

  1. Download the dedicated server from https://www.minecraft.net/en-us/download/server

  2. Start the server twice on the same port (you might have to start them in separate folders)
    ❌ The second server shows a NullPointerException in the log

Linked issues

Comments 1

Can confirm in 1.19.4

The server now throws an IllegalStateException before the NullPointerException

[17:54:28] [Server thread/WARN]: **** FAILED TO BIND TO PORT!
[17:54:28] [Server thread/WARN]: The exception was: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
[17:54:28] [Server thread/WARN]: Perhaps a server is already running on that port?
[17:54:28] [Server thread/ERROR]: Encountered an unexpected exception
java.lang.IllegalStateException: Failed to initialize server
        at net.minecraft.server.MinecraftServer.runServer(SourceFile:688) ~[server-1.19.4.jar:?]
        at net.minecraft.server.MinecraftServer.lambda$spin$2(SourceFile:266) ~[server-1.19.4.jar:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]
[17:54:28] [Server thread/ERROR]: This crash report has been saved to: /home/finn/vanilla/./crash-reports/crash-2023-03-20_17.54.28-server.txt
[17:54:28] [Server thread/INFO]: Stopping server
[17:54:28] [Server thread/INFO]: Saving worlds
[17:54:28] [Server thread/ERROR]: Exception stopping the server
java.lang.NullPointerException: Cannot invoke "net.minecraft.server.level.ServerLevel.getWorldBorder()" because "$$5" is null
        at net.minecraft.server.MinecraftServer.saveAllChunks(SourceFile:545) ~[server-1.19.4.jar:?]
        at net.minecraft.server.MinecraftServer.stopServer(SourceFile:606) ~[server-1.19.4.jar:?]
        at net.minecraft.server.dedicated.DedicatedServer.stopServer(SourceFile:536) ~[server-1.19.4.jar:?]
        at net.minecraft.server.MinecraftServer.runServer(SourceFile:707) ~[server-1.19.4.jar:?]
        at net.minecraft.server.MinecraftServer.lambda$spin$2(SourceFile:266) ~[server-1.19.4.jar:?]
        at java.lang.Thread.run(Thread.java:833) ~[?:?]

marcono1234

(Unassigned)

Confirmed

Platform

Low

Dedicated Server

Minecraft 19w04b, 1.15.2, 1.17, 1.17.1 Pre-release 1, 1.17.1, 1.18.2 Release Candidate 1, 1.18.2, 22w12a, 1.19.4

Retrieved