[SPIGOT-6111] NPE in CraftHumanEntity#openWorkbench & CraftHumanEntity#openEnchanting Created: 27/Aug/20  Updated: 27/Aug/20  Resolved: 27/Aug/20

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: JRoy Assignee: md_5
Resolution: Fixed Votes: 0
Labels: api
Environment:

N/A


Version: N/A
Guidelines Read: Yes

 Description   

In the implementation for openWorkbench and openEnchanting in CraftHumanEntity, the location null check is below the first use of the location object. This will create an NPE if the location parameter is null and the force parameter is false.

Player player = Bukkit.getPlayer("md_5");
player.openWorkbench(null, false); //Throws NPE 

Can be fixed by moving the location null check above force check like so.

 

if (!force) {
    Block block = location.getBlock();
    if (block.getType() != Material.CRAFTING_TABLE) {
        return null;
    }
}
if (location == null) {
    location = getLocation();
}

// becomes

if (location == null) {
    location = getLocation();
}
if (!force) {
    Block block = location.getBlock();
    if (block.getType() != Material.CRAFTING_TABLE) {
        return null;
    }
}

 

 



 Comments   
Comment by JRoy [ 27/Aug/20 ]

Ignore title  just checked git blame and looks like this has been unnoticed since the concept of the Inventory API

Comment by md_5 [ 27/Aug/20 ]

Regression from when?

Generated at Sat Apr 05 09:38:27 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.