On Mon, Dec 6, 2021 at 8:10 AM Thiago Henrique Hupner <thi...@gmail.com> wrote: > > Hi all. > > I've found something weird. > If I try to "reflect" a MethodHandle.arrayElementGetter, the method > returned is not accessible, so I need to call setAccessible to be able to > use it. > The same happens to arrayElementSetter, > > I'd like to know if this is the expected behavior. I was assuming that > it would return me some java.lang.reflect.Array, but it seems to be > returning > an internal implementation.
This is expected behaviour. The MethodHandle::arrayElementGetter & ::arrayElementSetter methods produce a MethodHandle that reads / writes an array element "as if by the aaload / aastore bytecode". Those "as if" words are key as the design intent behind MethodHandles is that they operate as close to the bytecode semantics as possible. The j.l.r.Array implementations are native methods so binding to them - and, at least conceptually, wrapping them with an MH::asType operation to correct the signature - would be less performant than the bytecode based access the current implementation supports. Huge caveats apply to this reasoning. MethodHandles that aren't directly looked up using a MHs::Lookup are generally not intended to be cracked and the result may change from release to release as better implementations get explored. --Dan