Skip to content

Commit 7272e15

Browse files
committed
Fixed Method invocation 'getX' may produce 'NullPointerException'
The warning occured because `delivery.getBlockPos()` might return null, leading to a `NullPointerException` when calling `pos.getX()`. Although `isBlockTarget()` checks for non-null `blockPos`, the static analyzer doesn't recognize this invariant. Solved it by adding a null check for `delivery.getBlockPos()` in the `applyTargeted` method. Only proceed with sound playback if `pos` is not null. The null check if `(pos != null)` ensures `pos.getX()` won't be called on a null reference. This satisfies the static analyzer while maintaining the existing logic since `isBlockTarget()` already implies `blockPos` shouldn't be null. The check acts as a safeguard against potential future changes to `TargetedSpellDelivery`.
1 parent ebb2f7a commit 7272e15

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/main/java/dev/overgrown/thaumaturge/spell/impl/victus/VictusEffect.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public void applyTargeted(TargetedSpellDelivery delivery) {
3535
applyVictusEffect(target, getPowerMultiplier(delivery.getModifiers()), delivery.getCaster());
3636
} else if (delivery.isBlockTarget()) {
3737
BlockPos pos = delivery.getBlockPos();
38-
playSound(delivery.getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
38+
if (pos != null) { // Null check added here
39+
playSound(delivery.getWorld(), pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
40+
}
3941
}
4042
}
4143

0 commit comments

Comments
 (0)