Integrated Dynamics

Integrated Dynamics

63M Downloads

Test for null instead of catching NullPointerException

josephcsible opened this issue ยท 0 comments

commented

try {
Entity entity = a.getRawValue().get();
EntityRegistry.EntityRegistration entityRegistration = EntityRegistry.instance().lookupModSpawn(entity.getClass(), true);
modName = entityRegistration.getContainer().getName();
} catch (NullPointerException e) {
modName = "Minecraft";
}

try {
Fluid fluid = a.getRawValue().get().getFluid();
String modDomain = null;
if (fluid.getStill() != null) {
modDomain = fluid.getStill().getResourceDomain();
} else if (fluid.getFlowing() != null) {
modDomain = fluid.getFlowing().getResourceDomain();
} else if (fluid.getBlock() != null) {
modDomain = Block.REGISTRY.getNameForObject(fluid.getBlock()).getResourceDomain();
}
String modId = org.cyclops.cyclopscore.helper.Helpers.getModId(modDomain);
modName = Loader.instance().getIndexedModList().get(modId).getName();
} catch (NullPointerException e) {
modName = "Minecraft";
}

Exceptions are supposed to be exceptional. These need to be refactored into tests for null.