Skip to content

Suppress AccessController deprecation warning for Java 17+#682

Merged
xerial merged 2 commits into
mainfrom
fix-accesscontroller-deprecation
Jul 20, 2025
Merged

Suppress AccessController deprecation warning for Java 17+#682
xerial merged 2 commits into
mainfrom
fix-accesscontroller-deprecation

Conversation

@xerial
Copy link
Copy Markdown
Owner

@xerial xerial commented Jul 20, 2025

Summary

  • Suppresses the deprecation warning for java.security.AccessController that appears when compiling with Java 17+
  • Adds @SuppressWarnings("removal") annotation to the DirectByteBuffers class

Background

java.security.AccessController was deprecated for removal in Java 17 as part of JEP 411 (Deprecate the Security Manager for Removal). This causes the following warning during compilation:

[warn] java.security.AccessController in java.security has been deprecated and marked for removal

Solution

Since snappy-java needs to maintain compatibility with Java 8+ (as configured in build.sbt), we cannot remove the AccessController.doPrivileged calls. The best approach is to suppress the warning while maintaining backward compatibility.

The AccessController calls 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

  • Verified compilation succeeds without the AccessController warning
  • Existing tests continue to pass
  • Code remains compatible with Java 8+

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the DirectByteBuffers class. This change specifically addresses and suppresses the deprecation warning for java.security.AccessController that 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.doPrivileged calls (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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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+
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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>
@xerial
Copy link
Copy Markdown
Owner Author

xerial commented Jul 20, 2025

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.

@xerial
Copy link
Copy Markdown
Owner Author

xerial commented Jul 20, 2025

Thank you for the review @gemini-code-assist! I've addressed your feedback by applying the @SuppressWarnings("removal") annotations to the specific methods and code blocks that use AccessController, rather than at the class level. This provides more targeted suppression and avoids hiding other potential deprecation warnings in the class.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

You're welcome, @xerial! I appreciate you taking the time to address the feedback. Your approach of applying the @SuppressWarnings("removal") annotations to the specific methods and code blocks that utilize AccessController is indeed the best practice. This ensures that the suppression is precisely targeted, preventing the unintended hiding of other potential deprecation warnings within the class. Excellent work!

@gemini-code-assist
Copy link
Copy Markdown
Contributor

No further response is needed at this time. The author has addressed the feedback, and the previous comment from gemini-code-assist has acknowledged their excellent work.

@xerial xerial merged commit 83466aa into main Jul 20, 2025
9 checks passed
@xerial xerial deleted the fix-accesscontroller-deprecation branch July 20, 2025 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant