> Java lets you do many things programs may want to do in a memory-safe way but not everything.
Can you give an example of Java lets you do that is not memory-safe? Honestly, I don't really count the crazy off-heap tricks that some people use. It's almost like writing a Python library in pure C, intead of Python, then complaining that Python allows you to do non-memory-safe things.
Eh, I don't really count FFM. Would you have said JNI before Java 22? FFM is little more than a convenient wrapper around the same that can be dome with JNI.
Yes, I would have said JNI (and JNI still exists). But FFM is much more than a wrapper. In most situations it offers a significant performance boost over JNI. E.g. see https://github.com/Glavo/java-ffi-benchmark, which is a bit out of date, and FFM is even better now especially in the cases it was behind in those benchmarks.
Also, the integrity story is different for them. JNI is able to arbitrarily call Java methods and read/write variables, bypassing Java's access control. FFM doesn't. So really, the only integrity issue with FFM is the native code's own memory safety. With JNI, there are bigger risks (e.g. JNI can mutate Java strings).