From 83466aa5e033df46a656e7deb1535b8520ab708e Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Sun, 20 Jul 2025 11:59:59 -0700 Subject: [PATCH] Suppress AccessController deprecation warning for Java 17+ (#682) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Suppress AccessController deprecation warning AccessController has been deprecated for removal since Java 17 as part of JEP 411. Since snappy-java needs to maintain compatibility with Java 8+, we cannot remove the AccessController.doPrivileged calls. This commit adds @SuppressWarnings("removal") to suppress the deprecation warning while maintaining backward compatibility. The AccessController calls are used to bypass SecurityManager restrictions when cleaning DirectByteBuffers. In Java 17+, these calls effectively just run the action directly since SecurityManager is being phased out. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude * Apply @SuppressWarnings to specific methods instead of class level Based on review feedback, narrowed the scope of @SuppressWarnings("removal") annotations to only the specific methods and code blocks that use AccessController, rather than applying it at the class level. This approach: - Reduces the scope of the suppression - Avoids hiding other potential deprecation warnings - Follows best practices for targeted warning suppression 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java b/src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java index 2d77ed8..26b8411 100644 --- a/src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java +++ b/src/main/java/org/xerial/snappy/pool/DirectByteBuffers.java @@ -35,6 +35,7 @@ final class DirectByteBuffers { // and https://github.com/apache/lucene-solr/blob/7e03427fa14a024ce257babcb8362d2451941e21/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java MethodHandle cleanHandle = null; try { + @SuppressWarnings("removal") // AccessController is deprecated for removal in Java 17+ final PrivilegedExceptionAction action = new PrivilegedExceptionAction() { @Override @@ -90,7 +91,9 @@ final class DirectByteBuffers { } }; - cleanHandle = AccessController.doPrivileged(action); + @SuppressWarnings("removal") // AccessController is deprecated for removal in Java 17+ + MethodHandle temp = AccessController.doPrivileged(action); + cleanHandle = temp; } catch (Throwable t) { Logger.getLogger(DirectByteBuffers.class.getName()).log(Level.FINE, "Exception occurred attempting to lookup Sun specific DirectByteBuffer cleaner classes.", t); @@ -121,6 +124,7 @@ final class DirectByteBuffers { * * @param buffer The {@code ByteBuffer} to release. Must not be {@code null}. Must be {@link ByteBuffer#isDirect() direct}. */ + @SuppressWarnings("removal") // AccessController is deprecated for removal in Java 17+ public static void releaseDirectByteBuffer(final ByteBuffer buffer) { assert buffer != null && buffer.isDirect();