From 850b2f795820103237ede15ab2ff458867c88735 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 1 Aug 2018 23:14:22 -0400 Subject: [PATCH] Add disposal checks. --- .../natives/compression/NativeVelocityCompressor.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/native/src/main/java/com/velocitypowered/natives/compression/NativeVelocityCompressor.java b/native/src/main/java/com/velocitypowered/natives/compression/NativeVelocityCompressor.java index f14f016ed..d529900b4 100644 --- a/native/src/main/java/com/velocitypowered/natives/compression/NativeVelocityCompressor.java +++ b/native/src/main/java/com/velocitypowered/natives/compression/NativeVelocityCompressor.java @@ -1,5 +1,6 @@ package com.velocitypowered.natives.compression; +import com.google.common.base.Preconditions; import io.netty.buffer.ByteBuf; import java.util.zip.DataFormatException; @@ -18,6 +19,7 @@ public class NativeVelocityCompressor implements VelocityCompressor { @Override public void inflate(ByteBuf source, ByteBuf destination) throws DataFormatException { + ensureNotDisposed(); source.memoryAddress(); destination.memoryAddress(); @@ -38,6 +40,7 @@ public class NativeVelocityCompressor implements VelocityCompressor { @Override public void deflate(ByteBuf source, ByteBuf destination) throws DataFormatException { + ensureNotDisposed(); source.memoryAddress(); destination.memoryAddress(); @@ -56,6 +59,10 @@ public class NativeVelocityCompressor implements VelocityCompressor { deflate.finished = false; } + private void ensureNotDisposed() { + Preconditions.checkState(!disposed, "Object already disposed"); + } + @Override public void dispose() { if (!disposed) {