-
Notifications
You must be signed in to change notification settings - Fork 123
Description
When a Dbi
is created using a custom comparator it only works whilst a full GC has not run. This can be show by adding a System.gc()
between the construction of the map and the put
invocation in org.lmdbjava.DbiTest#customComparator
.
On executing put
it throws:
java.lang.NullPointerException: callable is null at jnr.ffi.provider.jffi.NativeClosureProxy.getCallable(NativeClosureProxy.java:57) at jnr.ffi.provider.jffi.NativeClosureProxy$$impl$$0.invoke(Unknown Source) at com.kenai.jffi.Foreign.invokeL5(Native Method) at com.kenai.jffi.Invoker.invokeL5(Invoker.java:438) at org.lmdbjava.Library$Lmdb$jnr$ffi$0.mdb_put(Unknown Source) at org.lmdbjava.Dbi.put(Dbi.java:421)
This happens since NativeClosureFactory.ClosureReference
is a WeakReference
and nothing else holds a reference to theComparatorCallback
.
I've tested that converting ComparatorCallback ccb
into a field fixes this, since it ensures the callback remains alive whilst the Dbi
object is accessible.