Compile-time warnings when compiling code that utilizes Unsafe
Olexandr Rotan
rotanolexandr842 at gmail.com
Mon May 6 19:10:34 UTC 2024
Sorry to put this message in another thread, I have just subscribed to
jdk-dev so dont have the initial thread in the box.
In this mail I would love to ask/propose to emit more verbose compile-time
warnings when compiled code uses deprecated Unsafe methods with suggestions
to replace it with corresponding alternatives in new APIs.
I am myself guilty of using private APIs and Unsafe particular in projects
for various reasons, but to be fair, I am not really familiar with most of
the low-level APIs. I think it's fairly common when people just find some
code snippet in a public repo or stackoverflow, paste it, see that it works
and proceed with the project. This people could find themself disoriented
when after updating to new Java version, Unsafe methods are just gone (or
does not compile). I am aware that in JEP alternatives for most if not all
replacements are described, but I think we all know that not every Java
developer keeps an eye on Java world updates to know where to look for
reliable information about intended substitutions.
As for now, If I understood everything correctly, warnings are only emitted
at runtime and do not contain any particular information on where and what
has been called exactly. Imo, this noninformative message does not carry
any particular info for people that write code using Unsafe and do not help
or encourage migrating to new APIs.
Best regards
PS: just checked the current state of things for a few methods, and
deprecation messages in Unsafe do not provide direct alternatives to
deprecated methods, just suggestions to migrate to xHandle classes or other
parts of new APIs.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20240506/c91f4536/attachment.htm>
More information about the jdk-dev
mailing list