CapabilityProviderFolder does not perform sanity check on actual capability instance
3TUSK opened this issue ยท 1 comments
Forwarded from Snownee/Cuisine#16.
We have received a crash-report that involves with this chunk of code from our mod, Cuisine:
ItemStack stack = inv.getStackInRowAndColumn(startX, startY);
FoodContainer container = stack.getCapability(CulinaryCapabilities.FOOD_CONTAINER, null);
if (container != null)
{
CompositeFood food = container.get();
if (food != null)
{
return !container.getEmptyContainer(stack).isEmpty();
}
}
return false;
Notice that the getCapability
call does not have a accompanied hasCapability
call. This is clarified and considered as permissible since MinecraftForge/MinecraftForge#4978, which is available since Forge 14.23.4.2733. As such, the getCapability
in CapabilityProviderFolder
has problematic implementation:
@Nullable
@Override
public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing)
{
return FOLDER_CAP.cast(folder);
}
Specifically, it does not check if the capability
token passed in is indeed the FOLDER_CAP
. A example crash may be found in the forwarded issue ticket.
Considering the fact that the recommended Forge version is 14.23.5.2768 as of the time I am writing this, please consider adding a check against the capability
instance (i.e. capability == FOLDER_CAP ? FOLDER_CAP.cast(folder) : null
).