Bukkit/CraftBukkit — comment on commit efad409200112e7d434db19198e4f6726c006b57
File: src/main/java/net/minecraft/server/InventoryPlayer.java line 315
By cstotts:

This doesn't seem to work for me. We still crash when the block is null because right below it you're calling itemstack.b(block)

The check that works for Precious Stones plugin is a pretty simple:
if(block == null) return false; at the top of the function.