Skip to content

Using Custom Comparator throws NullPointerException after GC #125

@jheister

Description

@jheister

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn issue relates to behaviour that violates the intention of the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions