Suppress AccessController deprecation warning for Java 17+#682
Conversation
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 <noreply@anthropic.com>
There was a problem hiding this comment.
Summary of Changes
Hello @xerial, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request focuses on resolving a compilation warning that occurs when building the project with Java 17 and later versions. The core change involves adding a specific annotation to suppress a deprecation warning related to AccessController, thereby ensuring a clean build process on newer Java runtimes while preserving essential functionality and compatibility with older Java versions.
Highlights
- Deprecation Warning Suppression: Added the
@SuppressWarnings("removal")annotation to theDirectByteBuffersclass. This change specifically addresses and suppresses the deprecation warning forjava.security.AccessControllerthat appears when compiling the project with Java 17 or newer versions. - Java Compatibility Maintenance: The approach taken ensures that the project remains fully compatible with Java 8+ environments. Instead of removing the
AccessController.doPrivilegedcalls (which are necessary for backward compatibility), the warning is suppressed, allowing the codebase to compile cleanly on modern Java versions without breaking older runtime support.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request addresses the deprecation warning for java.security.AccessController by adding a class-level @SuppressWarnings("removal") annotation. A suggestion is provided to narrow the scope of the suppression for better maintainability.
| /** | ||
| * Utility to facilitate disposing of direct byte buffer instances. | ||
| */ | ||
| @SuppressWarnings("removal") // AccessController is deprecated for removal in Java 17+ |
There was a problem hiding this comment.
Consider applying the @SuppressWarnings("removal") annotation to the specific methods or code blocks where AccessController is used, rather than at the class level. This reduces the scope of the suppression and avoids hiding other potential deprecation warnings in the class. For example, apply it to the releaseDirectByteBuffer method.
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 <noreply@anthropic.com>
|
Thank you for the review @gemini-code-assist! I've addressed your feedback by applying the annotations to the specific methods and code blocks that use , rather than at the class level. This provides more targeted suppression and avoids hiding other potential deprecation warnings in the class. |
|
Thank you for the review @gemini-code-assist! I've addressed your feedback by applying the |
|
You're welcome, @xerial! I appreciate you taking the time to address the feedback. Your approach of applying the |
|
No further response is needed at this time. The author has addressed the feedback, and the previous comment from |
Summary
java.security.AccessControllerthat appears when compiling with Java 17+@SuppressWarnings("removal")annotation to theDirectByteBuffersclassBackground
java.security.AccessControllerwas deprecated for removal in Java 17 as part of JEP 411 (Deprecate the Security Manager for Removal). This causes the following warning during compilation:Solution
Since snappy-java needs to maintain compatibility with Java 8+ (as configured in
build.sbt), we cannot remove theAccessController.doPrivilegedcalls. The best approach is to suppress the warning while maintaining backward compatibility.The
AccessControllercalls in this class 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.Test plan
🤖 Generated with Claude Code