replacements for Unsafe

Jochen Theodorou blackdrag at gmx.org
Wed Apr 29 11:23:47 UTC 2020


Hi,

when jigsaw started there was a lot of talk about providing alternatives
to what Unsafe offers. Today I am facing a problem I cannot solve
anymore it seems with this.

My problem is that I need to ensure the static block of an inner class
has been executed before I do something, because the static block
contains setup data the class will need and influence what I do with the
class. Of course this might be not the best choice, I am just trying to
keep certain functionality.

In the past I would have used Unsafe#ensureClassInitialized, but this
method has not found a replacement yet if I read JDK-8235521 :
Replacement API for Unsafe::ensureClassInitialized correctly.

Also because of Unsafe#getUnsafe, checking for the platform loader for
the caller (which is not the case for me) I cannot get the unsafe object
itself "properly".

Now I am wondering what alternatives exist. Are there any?

bye Jochen


More information about the jigsaw-dev mailing list