NPE at Clan.init (line 187) and Profile.lambda$init$0 (line 175) on startup with empty MongoDB #2

Closed
opened 2026-08-28 03:08:12 +00:00 by crypt · 1 comment
Owner

Issue

v1.1.6 fixed the Hotbar.init NPE, but there are now two new NPEs:

1. Clan.init NPE (startup failure)

[02:52:21 ERROR]: Error occurred while enabling WillowcrestPractice v1.1.6 (Is it up to date?)
java.lang.NullPointerException
	at world.willowcrest.practice.player.clan.Clan.init(Clan.java:187) ~[?:?]
	at world.willowcrest.practice.wPractice.initManagers(wPractice.java:207) ~[?:?]
	at world.willowcrest.practice.wPractice.onEnable(wPractice.java:152) ~[?:?]

This crashes during onEnable at Clan.init(Clan.java:187), called from initManagers(wPractice.java:207). The Hotbar.init crash was at wPractice.java:198 - Clan.init is the next manager being initialized (line 207 vs 198).

Also note this warning before the crash:

[02:52:21 WARN]: [WillowcrestPractice] No spigot compatible with wPractice's knockback-per-kit system; using default.

2. Profile.lambda$init$0 NPE (runtime task)

[02:52:23 WARN]: [WillowcrestPractice] Task #12 for WillowcrestPractice v1.1.6 generated an exception
java.lang.NullPointerException
	at world.willowcrest.practice.player.profile.Profile.lambda$init$0(Profile.java:175) ~[?:?]
	at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:64) ~[?:?]
	at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:409) ~[?:?]

This runs as a scheduled task (Task #12) about 2 seconds after startup. Likely an async profile initialization that depends on MongoDB data being present.

Environment (unchanged from issue #1)

  • SportPaper 1.8.8 (Java 8)
  • MongoDB 7 at mongo-minecraft.minecraft.svc.cluster.local:27017 (no auth, database: practice)
  • MongoDB connection succeeds (logs confirm state=CONNECTED)
  • Fresh MongoDB instance with no pre-existing data
  • Plugin v1.1.6 deployed via PLUGINS_FILE

Player Login

A player did connect successfully (sqw logged in with entity id 316) and ran /plugins and /wpractice, but the plugin is in a partially broken state due to the Clan.init crash during onEnable.

Pattern

Same pattern as the Hotbar.init bug: a manager init method NPEs on an empty MongoDB database. The Clan manager (line 207) is likely querying MongoDB for clan data and getting null back on an empty database, similar to how Hotbar.init failed.

The Profile NPE (Task #12) may be related - if the plugin doesn't fully initialize due to the Clan crash, the profile scheduled task may be running against partially-initialized state.

## Issue v1.1.6 fixed the Hotbar.init NPE, but there are now two new NPEs: ### 1. Clan.init NPE (startup failure) ``` [02:52:21 ERROR]: Error occurred while enabling WillowcrestPractice v1.1.6 (Is it up to date?) java.lang.NullPointerException at world.willowcrest.practice.player.clan.Clan.init(Clan.java:187) ~[?:?] at world.willowcrest.practice.wPractice.initManagers(wPractice.java:207) ~[?:?] at world.willowcrest.practice.wPractice.onEnable(wPractice.java:152) ~[?:?] ``` This crashes during `onEnable` at `Clan.init(Clan.java:187)`, called from `initManagers(wPractice.java:207)`. The Hotbar.init crash was at `wPractice.java:198` - Clan.init is the next manager being initialized (line 207 vs 198). Also note this warning before the crash: ``` [02:52:21 WARN]: [WillowcrestPractice] No spigot compatible with wPractice's knockback-per-kit system; using default. ``` ### 2. Profile.lambda$init$0 NPE (runtime task) ``` [02:52:23 WARN]: [WillowcrestPractice] Task #12 for WillowcrestPractice v1.1.6 generated an exception java.lang.NullPointerException at world.willowcrest.practice.player.profile.Profile.lambda$init$0(Profile.java:175) ~[?:?] at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:64) ~[?:?] at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:409) ~[?:?] ``` This runs as a scheduled task (Task #12) about 2 seconds after startup. Likely an async profile initialization that depends on MongoDB data being present. ## Environment (unchanged from issue #1) - SportPaper 1.8.8 (Java 8) - MongoDB 7 at `mongo-minecraft.minecraft.svc.cluster.local:27017` (no auth, database: `practice`) - MongoDB connection succeeds (logs confirm `state=CONNECTED`) - Fresh MongoDB instance with no pre-existing data - Plugin v1.1.6 deployed via `PLUGINS_FILE` ## Player Login A player did connect successfully (`sqw logged in with entity id 316`) and ran `/plugins` and `/wpractice`, but the plugin is in a partially broken state due to the Clan.init crash during onEnable. ## Pattern Same pattern as the Hotbar.init bug: a manager init method NPEs on an empty MongoDB database. The Clan manager (line 207) is likely querying MongoDB for clan data and getting null back on an empty database, similar to how Hotbar.init failed. The Profile NPE (Task #12) may be related - if the plugin doesn't fully initialize due to the Clan crash, the profile scheduled task may be running against partially-initialized state.
crypt closed this issue 2026-08-28 03:18:41 +00:00
Author
Owner

Fixed in v1.1.7 → https://git.willowcrest.world/crypt/minecraft-practice-pvp/releases/tag/v1.1.7

Root cause: wPractice.mongoDatabase was never assigned from MongoConnection.getMongoDatabase() after creating the connection in loadSaveMethod(). Every call to wPractice.get().getMongoDatabase() returned null, causing the NPEs in Clan.init() (line 187) and Profile.init() (line 175).

Secondary issue: MongoConnection's constructors swallowed all exceptions with catch (Exception e) { e.printStackTrace(); }, so loadSaveMethod()'s catch handler never saw connection failures — the plugin stayed enabled with a null database instead of disabling gracefully.

Fixes applied:

  • Wire this.mongoDatabase = this.mongoConnection.getMongoDatabase() after connection, with null check that throws IllegalStateException to trigger loadSaveMethod's graceful disable
  • Removed swallowed catch in MongoConnection — exceptions now propagate
  • Fixed non-URI constructors to properly store the mongo client
  • Added null guards in Clan.init() and Profile.init() as defense-in-depth
Fixed in **v1.1.7** → https://git.willowcrest.world/crypt/minecraft-practice-pvp/releases/tag/v1.1.7 **Root cause:** `wPractice.mongoDatabase` was never assigned from `MongoConnection.getMongoDatabase()` after creating the connection in `loadSaveMethod()`. Every call to `wPractice.get().getMongoDatabase()` returned null, causing the NPEs in `Clan.init()` (line 187) and `Profile.init()` (line 175). **Secondary issue:** `MongoConnection`'s constructors swallowed all exceptions with `catch (Exception e) { e.printStackTrace(); }`, so `loadSaveMethod()`'s catch handler never saw connection failures — the plugin stayed enabled with a null database instead of disabling gracefully. **Fixes applied:** - Wire `this.mongoDatabase = this.mongoConnection.getMongoDatabase()` after connection, with null check that throws `IllegalStateException` to trigger `loadSaveMethod`'s graceful disable - Removed swallowed catch in `MongoConnection` — exceptions now propagate - Fixed non-URI constructors to properly store the mongo client - Added null guards in `Clan.init()` and `Profile.init()` as defense-in-depth
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
crypt/minecraft-practice-pvp#2
No description provided.