Fix resulting buffer from BufferProxy's out method being ignored. by LambdAurora · Pull Request #255 · lmdbjava/lmdbjava
This pull request aims to fix some cases in LMDBJava where the BufferProxy's out method resulting buffer is ignored, especially in Dbi.
I've discovered this issue while attempting to write a new implementation of BufferProxy to use Java 22's Function Foreign Memory API in preparation of Java 25's depreciation of various methods in Unsafe invalidating most fast BufferProxy implementations. The implementation failed to pass some tests since in the out method I returned a new ByteBuffer (taking advantage of MemorySegment.ofAddress().asByteBuffer()).
After further investigation, I've found that ByteArrayProxy also relies on returning a different "buffer" from the one that's given as an argument, for which I've added new tests that reproduce the behavior of DbiTest.customComparator and DbiTest.dbiWithComparatorThreadSafety using byte arrays instead. ByteArrayProxy led me to think that returning a different buffer in out is an allowed and intended behavior.
This fix is important for users of ByteArrayProxy and allows for a stop-gap external implementation of BufferProxy using the FFM API to allow users to upgrade to Java 25 when the time comes until a proper resolution to #42 comes around.