BuildCraft|Core

BuildCraft|Core

7M Downloads

Add protection against potential world corruption

SpaceToad opened this issue ยท 8 comments

commented

https://github.com/BuildCraft/BuildCraft/blob/NextGen/common/buildcraft/builders/BlockMarker.java#L115

TileEntity te = world.getTileEntity(x, y, z);
if(te != null && te instanceof TileMarker)
{
        ((TileMarker) world.getTileEntity(x, y, z)).updateSignals();
}

Should avoid crash.

commented

Yup, definitely :-) There's probably a bit more code review to be made on blocks, to identify other similar situations. If you feel like it, let me know!

commented

'instanceof' keyword returns false if your variable is null. So you can do just
if(te instanceof TileMarker) thing.

commented

Yup - that's what this issue is about ;-)

commented

@anti344 thank ! I got into the habit of putting a null check because of ItemStack ( if(stack != null && stack.getItem() == SomeThing)), but as here we do not call a method it is true that the null check is unnecessary.

commented

if(stack.getItem() != null && stack.getItem() == SomeThing)

That doesn't make sense. Perhaps you meant if (stack != null...

instanceof is a costly operation. The tile entity shouldn't be anything other than the one expected, if something like that happens then there is a bug somewhere. So checking for null should be enough.

commented

That doesn't make sense. Perhaps you meant if (stack != null...

Indeed x) I edited my last post.

So checking for null should be enough.

No, if the tile entity was null, there will have been a NullPointerException and not a ClassCastException. the tile entity is not null, it was not the right, so only a instanceof can fix the crash. But it is true that this should not happen under normal circumstances, it should not have a pipe tile entity on a marker ...