I think we're saved mostly from really bad bugs by the strict instance equality check in ItemStack.isEmpty, but nonetheless this should be fixed.
You can see this happening by inserting the following code below the public ItemStack constructors:
private void E() {
if (this.h && this == ItemStack.a) throw new AssertionError("TRAP"); // CraftBukkit
this.h = false;
this.h = this.isEmpty();
}And then right clicking a block with a sword.
Comments 4
It happens even more frequently in 1.15 because the ItemStack clone method was updated to return the EMPTY constant, so now it also shows up in places that were manipulating cloned stacks.
Fixed in 23w14a. The cached "empty" flag on item stacks no longer exists, so the constant empty stack can't be modified that way anymore.
Only confirmed that the method still exists in this form and could cause problems, but not that it is currently actually called.