Polymer

Polymer

763k Downloads

NullPointerException when calling `PalettedContainer.Data.writePacket` without context

senseiwells opened this issue ยท 1 comments

commented

This issue is regarding a compatibility issue with ServerReplay.

With ServerReplay it's possible to write packets without a player context (i.e. ChunkRecordings).

Here is a stacktrace relevant to this issue: https://mclo.gs/lNA4M4I

var player = PacketContext.get();
if (player.getPacketListener() == null) {
return storage;
}
int bits;
var playerBitCount = PolymerServerNetworking.getMetadata(player.getClientConnection(), ClientMetadataKeys.BLOCKSTATE_BITS, NbtInt.TYPE);

In this snippet the result of PacketContext.get() is a reference to the MutableContext thread local instance, which by default returns ContextProvidingPacketListener.EMPTY on the getPacketListener() call, not null, getPacketListener() is not marked @Nullable so this check is redundant. This results in PolymerServerNetworking.getMetadata throwing a NullPointerException since there's no actual connection context.

I believe this should be replaced with a getBackingPacketListener() call instead.

Even in the case where there is no context should polymer still not replace the block states, just without the player?

commented

Due to it happening in packet, it should convert it but lack of context will change how other mods will handle it