Skip to content

Commit 40be3e6

Browse files
BoxStore: re-set handle value on close to avoid native crash on access.
1 parent 789e99a commit 40be3e6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

objectbox-java/src/main/java/io/objectbox/BoxStore.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static boolean isSyncServerAvailable() {
221221
private final File directory;
222222
private final String canonicalPath;
223223
/** Reference to the native store. Should probably get through {@link #getNativeStore()} instead. */
224-
private final long handle;
224+
private long handle;
225225
private final Map<Class<?>, String> dbNameByClass = new HashMap<>();
226226
private final Map<Class<?>, Integer> entityTypeIdByClass = new HashMap<>();
227227
private final Map<Class<?>, EntityInfo<?>> propertiesByClass = new HashMap<>();
@@ -626,7 +626,9 @@ public void close() {
626626
}
627627
if (handle != 0) { // failed before native handle was created?
628628
nativeDelete(handle);
629-
// TODO set handle to 0 and check in native methods
629+
// The Java API has open checks, but just in case re-set the handle so any native methods will
630+
// not crash due to an invalid pointer.
631+
handle = 0;
630632
}
631633

632634
// When running the full unit test suite, we had 100+ threads before, hope this helps:

0 commit comments

Comments
 (0)