From 89f98ce57de0d87da00ef9793ee16f4ce03cb479 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 29 Jul 2020 05:34:15 -0400 Subject: [PATCH] Make Disposable interface implement Closeable --- .../main/java/com/velocitypowered/natives/Disposable.java | 7 +++++-- .../natives/compression/Java11VelocityCompressor.java | 2 +- .../natives/compression/JavaVelocityCompressor.java | 2 +- .../natives/compression/LibdeflateVelocityCompressor.java | 2 +- .../natives/encryption/JavaVelocityCipher.java | 2 +- .../natives/encryption/NativeVelocityCipher.java | 2 +- .../natives/compression/VelocityCompressorTest.java | 5 ++--- .../natives/encryption/VelocityCipherTest.java | 5 ++--- .../proxy/protocol/netty/MinecraftCipherDecoder.java | 2 +- .../proxy/protocol/netty/MinecraftCipherEncoder.java | 2 +- .../proxy/protocol/netty/MinecraftCompressDecoder.java | 2 +- .../proxy/protocol/netty/MinecraftCompressEncoder.java | 2 +- 12 files changed, 18 insertions(+), 17 deletions(-) diff --git a/native/src/main/java/com/velocitypowered/natives/Disposable.java b/native/src/main/java/com/velocitypowered/natives/Disposable.java index 1aad8597e..16952d915 100644 --- a/native/src/main/java/com/velocitypowered/natives/Disposable.java +++ b/native/src/main/java/com/velocitypowered/natives/Disposable.java @@ -1,16 +1,19 @@ package com.velocitypowered.natives; +import java.io.Closeable; + /** * This marker interface indicates that this object should be explicitly disposed before the object * can no longer be used. Not disposing these objects will likely leak native resources and * eventually lead to resource exhaustion. */ -public interface Disposable { +public interface Disposable extends Closeable { /** * Disposes this object. After this call returns, any use of this object becomes invalid. Multiple * calls to this function should be safe: there should be no side-effects once an object is * disposed. */ - void dispose(); + @Override + void close(); } diff --git a/native/src/main/java/com/velocitypowered/natives/compression/Java11VelocityCompressor.java b/native/src/main/java/com/velocitypowered/natives/compression/Java11VelocityCompressor.java index bc6206242..18397fee7 100644 --- a/native/src/main/java/com/velocitypowered/natives/compression/Java11VelocityCompressor.java +++ b/native/src/main/java/com/velocitypowered/natives/compression/Java11VelocityCompressor.java @@ -123,7 +123,7 @@ public class Java11VelocityCompressor implements VelocityCompressor { } @Override - public void dispose() { + public void close() { disposed = true; deflater.end(); inflater.end(); diff --git a/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java b/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java index f2e557d1c..d5ad754b9 100644 --- a/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java +++ b/native/src/main/java/com/velocitypowered/natives/compression/JavaVelocityCompressor.java @@ -118,7 +118,7 @@ public class JavaVelocityCompressor implements VelocityCompressor { } @Override - public void dispose() { + public void close() { disposed = true; deflater.end(); inflater.end(); diff --git a/native/src/main/java/com/velocitypowered/natives/compression/LibdeflateVelocityCompressor.java b/native/src/main/java/com/velocitypowered/natives/compression/LibdeflateVelocityCompressor.java index 0638f5320..e748fd70b 100644 --- a/native/src/main/java/com/velocitypowered/natives/compression/LibdeflateVelocityCompressor.java +++ b/native/src/main/java/com/velocitypowered/natives/compression/LibdeflateVelocityCompressor.java @@ -70,7 +70,7 @@ public class LibdeflateVelocityCompressor implements VelocityCompressor { } @Override - public void dispose() { + public void close() { if (!disposed) { inflate.free(inflateCtx); deflate.free(deflateCtx); diff --git a/native/src/main/java/com/velocitypowered/natives/encryption/JavaVelocityCipher.java b/native/src/main/java/com/velocitypowered/natives/encryption/JavaVelocityCipher.java index 70ead996d..3b9d6d12c 100644 --- a/native/src/main/java/com/velocitypowered/natives/encryption/JavaVelocityCipher.java +++ b/native/src/main/java/com/velocitypowered/natives/encryption/JavaVelocityCipher.java @@ -55,7 +55,7 @@ public class JavaVelocityCipher implements VelocityCipher { } @Override - public void dispose() { + public void close() { disposed = true; } diff --git a/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java b/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java index 48e588ed6..bee59ac7a 100644 --- a/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java +++ b/native/src/main/java/com/velocitypowered/natives/encryption/NativeVelocityCipher.java @@ -39,7 +39,7 @@ public class NativeVelocityCipher implements VelocityCipher { } @Override - public void dispose() { + public void close() { if (!disposed) { impl.free(ctx); } diff --git a/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java b/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java index 2bc657b0f..735d216ba 100644 --- a/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java +++ b/native/src/test/java/com/velocitypowered/natives/compression/VelocityCompressorTest.java @@ -4,7 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.condition.OS.LINUX; -import static org.junit.jupiter.api.condition.OS.MAC; import com.velocitypowered.natives.util.BufferPreference; import com.velocitypowered.natives.util.Natives; @@ -43,7 +42,7 @@ class VelocityCompressorTest { void nativeIntegrityCheck() throws DataFormatException { VelocityCompressor compressor = Natives.compress.get().create(Deflater.DEFAULT_COMPRESSION); if (compressor.preferredBufferType() != BufferPreference.DIRECT_REQUIRED) { - compressor.dispose(); + compressor.close(); fail("Loaded regular compressor"); } check(compressor, () -> Unpooled.directBuffer(TEST_DATA.length + 32)); @@ -97,7 +96,7 @@ class VelocityCompressorTest { source.release(); dest.release(); decompressed.release(); - compressor.dispose(); + compressor.close(); } } } \ No newline at end of file diff --git a/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java b/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java index 2c48ca99a..0e76bdd0a 100644 --- a/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java +++ b/native/src/test/java/com/velocitypowered/natives/encryption/VelocityCipherTest.java @@ -12,7 +12,6 @@ import java.util.Random; import java.util.function.Supplier; import javax.crypto.spec.SecretKeySpec; import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; class VelocityCipherTest { @@ -62,8 +61,8 @@ class VelocityCipherTest { } finally { source.release(); workingBuf.release(); - decrypt.dispose(); - encrypt.dispose(); + decrypt.close(); + encrypt.close(); } } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java index 3eca73b4b..6a8e5158d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherDecoder.java @@ -30,6 +30,6 @@ public class MinecraftCipherDecoder extends MessageToMessageDecoder { @Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { - cipher.dispose(); + cipher.close(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java index ecaf9adb6..8a5983b22 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCipherEncoder.java @@ -30,6 +30,6 @@ public class MinecraftCipherEncoder extends MessageToMessageEncoder { @Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { - cipher.dispose(); + cipher.close(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java index 5a0e0462d..a083a9291 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressDecoder.java @@ -58,6 +58,6 @@ public class MinecraftCompressDecoder extends MessageToMessageDecoder { @Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { - compressor.dispose(); + compressor.close(); } } diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java index b0d9fd37b..0c3bcc0f2 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/netty/MinecraftCompressEncoder.java @@ -47,6 +47,6 @@ public class MinecraftCompressEncoder extends MessageToByteEncoder { @Override public void handlerRemoved(ChannelHandlerContext ctx) throws Exception { - compressor.dispose(); + compressor.close(); } }