[SPIGOT-4302] Setting an item in an unplaced furnace results in a NullPointerException Created: 22/Aug/18  Updated: 26/Aug/18  Resolved: 26/Aug/18

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

Type: Bug Priority: Minor
Reporter: Pieter12345 Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: exception, furnace, inventory

Version: git-Bukkit-ec86574 (MC: 1.13)
Guidelines Read: Yes

 Description   

When setting an item in the inventory of an unplaced furnace, a NullPointerException is thrown due to the world being null.

 

This exception is throws in method `s()` on line:
`FurnaceRecipe furnacerecipe = (FurnaceRecipe) this.world.D().b(this, this.world);`

in the NMS.TileEntityFurnace class, due to `this.world` being null.

This exception triggers at least on line `this.cookTimeTotal = this.s();` call in the `setItem(int, ItemStack)` method in the NMS.TileEntityFurnace class, which is called when setting an item through the Bukkit/Spigot API.

 

Reproduce code:

org.bukkit.block.Furnace furnace = (org.bukkit.block.Furnace) ((org.bukkit.inventory.meta.BlockStateMeta) new org.bukkit.inventory.ItemStack(org.bukkit.Material.FURNACE).getItemMeta()).getBlockState();
org.bukkit.inventory.ItemStack itemStack = new org.bukkit.inventory.ItemStack(org.bukkit.Material.STONE);
furnace.getInventory().setSmelting(itemStack);

 

Proposed solution:
Add a `this.world == null` check in the `s()` method and set `this.cookTimeTotal` on-place instead (if this does not happen already).



 Comments   
Comment by Pieter12345 [ 26/Aug/18 ]

Sorry for that, I used groovy to execute that code and the groovy interpreter does not require casts. I've added the missing cast.

Comment by md_5 [ 26/Aug/18 ]

FYI that code doesn't even compile.
Please take some care

Comment by Pieter12345 [ 26/Aug/18 ]

Added reproduction code.

Comment by md_5 [ 22/Aug/18 ]

No code

Generated at Fri Mar 14 09:44:34 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.