NullPointerException at Hotbar.init on server startup with empty MongoDB #1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Environment
The practice server is now deployed in the Willowcrest Kubernetes cluster:
minecraftnamespace (mongo-minecraft.minecraft.svc.cluster.local:27017, no auth)PLUGINS_FILEIssue
WillowcrestPractice v1.1.5 crashes during
onEnablewith aNullPointerExceptionatHotbar.init(Hotbar.java:57). The MongoDB connection succeeds (logs showMonitor thread successfully connected to serverandstate=CONNECTED), but the plugin crashes immediately after during Hotbar initialization.Stack Trace
Analysis
Opened connectionandMonitor thread successfully connectedlines come AFTER the NPE in the log, which suggests the MongoDB client is initializing asynchronously andHotbar.initis trying to use a MongoDB-dependent object before the connection is fully ready, or the Hotbar code assumes some MongoDB query returns non-null when the database is empty).hotbar.ymlconfig file exists and has valid content (all hotbar items defined with slots, materials, names).practicedatabase doesn't exist yet until the plugin creates collections.Likely Cause
Hotbar.init(Hotbar.java:57)is probably querying MongoDB for some data (e.g., player hotbar preferences or kit configurations) and gettingnullback because the database is empty. The code at line 57 likely doesn't handle the null case.How to Reproduce
kubectl rollout restart statefulset/practice -n minecraftkubectl logs -n minecraft practice-0 | grep -A5 "WillowcrestPractice"Hotbar.initwill appearWhat's Working
Infrastructure (for reference)
mongo-minecraft.minecraft.svc.cluster.local:27017(no auth, database name:practice)database.ymlconfig is at/data/plugins/WillowcrestPractice/database.ymlon the podFixed in v1.1.6.
Root cause: The shipped
hotbar.ymlhad noENABLEDkeys on any hotbar item.config.getBoolean(path + "ENABLED")returnsfalsewhen the key is missing, so no items were added to theitemsmap. When the dynamic content loop tried to look upMAP_SELECTIONto extract the%MAP%pattern, it gotnulland NPE'd at.getItemStack().Fix:
getBoolean(path + "ENABLED", true)— defaults to enabled when the key is missingENABLED: trueandSLOT: 0toMAP_SELECTIONandKIT_SELECTIONinhotbar.yml