Account for packet potentially being null in the PacketErrorEvent
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Deploy / build (push) Has been cancelled

This commit is contained in:
onebeastchris 2024-12-23 02:58:28 +08:00
parent 29f4e867de
commit ba6b90c288
2 changed files with 4 additions and 4 deletions

View file

@ -18,10 +18,10 @@ public class PacketErrorEvent implements SessionEvent {
* @param session Session that the error came from.
* @param cause Cause of the error.
*/
public PacketErrorEvent(Session session, Throwable cause, @Nullable Class<? extends Packet> packetClass) {
public PacketErrorEvent(Session session, Throwable cause, @Nullable Packet packetClass) {
this.session = session;
this.cause = cause;
this.packetClass = packetClass;
this.packetClass = packetClass == null ? null : packetClass.getClass();
}
/**

View file

@ -57,7 +57,7 @@ public class TcpPacketCodec extends MessageToMessageCodec<ByteBuf, Packet> {
} catch (Throwable t) {
log.debug(marker, "Error encoding packet", t);
PacketErrorEvent e = new PacketErrorEvent(this.session, t, packet.getClass());
PacketErrorEvent e = new PacketErrorEvent(this.session, t, packet);
this.session.callEvent(e);
if (!e.shouldSuppress()) {
throw new EncoderException(t);
@ -104,7 +104,7 @@ public class TcpPacketCodec extends MessageToMessageCodec<ByteBuf, Packet> {
// Advance buffer to end to make sure remaining data in this packet is skipped.
buf.readerIndex(buf.readerIndex() + buf.readableBytes());
PacketErrorEvent e = new PacketErrorEvent(this.session, t, packet.getClass());
PacketErrorEvent e = new PacketErrorEvent(this.session, t, packet);
this.session.callEvent(e);
if (!e.shouldSuppress()) {
throw new DecoderException(t);