u/hungarian_notation

Is there a way to opt-in to sun.misc.Unsafe deprecation early without a command line argument?

solved: /u/davidalayachew to the rescue with the @argfile syntax I was unaware of.


This question has been frustratingly difficult to research. Plenty of content out there from people who want to keep using their unsafe access without warnings, but I'm in a different camp.

A couple of tools I maintain use Guice (to my great Misery).

Guice is doing a really neat thing where it doesn't actually NEED sun.misc.Unsafe, but it's using it anyway. If I specify --sun-misc-unsafe-memory-access=deny the only thing that breaks is some absolutely bizzare error message enhancement they're implementing with ASM. The problem is that the library is either doing some preemptive checks for Unsafe features or is still using them preferentially, even under JDK 25 and 26.

Telling my users to just ignore the warnings and telling them to use that monstrosity of a command line flag are equally unsatisfying.

The only clear answer I can see, and the one I'm seriously considering, is adding a java agent to my app with the sole purpose of dynamically rewriting all the uses of sun.misc.Unsafe to throw UnsupportedOperationExceptions.

Before I go off the deep end with that, has anybody dealing with a similar situation come up with a more elegant solution?

reddit.com
u/hungarian_notation — 6 days ago