Skip to content

Commit 1e93772

Browse files
BoxStore: access context and relinker fields through methods.
However, still setting static field from constructor. Not sure of better solution, yet.
1 parent 14f8458 commit 1e93772

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
public class BoxStore implements Closeable {
6161

6262
/** On Android used for native library loading. */
63-
@Nullable public static Object context;
64-
@Nullable public static Object relinker;
63+
@Nullable private static Object context;
64+
@Nullable private static Object relinker;
6565

6666
/** Change so ReLinker will update native library when using workaround loading. */
6767
public static final String JNI_VERSION = "2.6.0-RC";
@@ -73,6 +73,18 @@ public class BoxStore implements Closeable {
7373
private static final Set<String> openFiles = new HashSet<>();
7474
private static volatile Thread openFilesCheckerThread;
7575

76+
@Nullable
77+
@Internal
78+
public static synchronized Object getContext() {
79+
return context;
80+
}
81+
82+
@Nullable
83+
@Internal
84+
public static synchronized Object getRelinker() {
85+
return relinker;
86+
}
87+
7688
/**
7789
* Convenience singleton instance which gets set up using {@link BoxStoreBuilder#buildDefault()}.
7890
* <p>

objectbox-java/src/main/java/io/objectbox/internal/NativeLibraryLoader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,22 @@ private static void checkUnpackLib(String filename) {
181181
}
182182

183183
private static boolean loadLibraryAndroid() {
184-
if (BoxStore.context == null) {
184+
if (BoxStore.getContext() == null) {
185185
return false;
186186
}
187187

188188
//noinspection TryWithIdenticalCatches
189189
try {
190190
Class<?> context = Class.forName("android.content.Context");
191-
if (BoxStore.relinker == null) {
191+
if (BoxStore.getRelinker() == null) {
192192
// use default ReLinker
193193
Class<?> relinker = Class.forName("com.getkeepsafe.relinker.ReLinker");
194194
Method loadLibrary = relinker.getMethod("loadLibrary", context, String.class, String.class);
195-
loadLibrary.invoke(null, BoxStore.context, OBJECTBOX_JNI, BoxStore.JNI_VERSION);
195+
loadLibrary.invoke(null, BoxStore.getContext(), OBJECTBOX_JNI, BoxStore.JNI_VERSION);
196196
} else {
197197
// use custom ReLinkerInstance
198-
Method loadLibrary = BoxStore.relinker.getClass().getMethod("loadLibrary", context, String.class, String.class);
199-
loadLibrary.invoke(BoxStore.relinker, BoxStore.context, OBJECTBOX_JNI, BoxStore.JNI_VERSION);
198+
Method loadLibrary = BoxStore.getRelinker().getClass().getMethod("loadLibrary", context, String.class, String.class);
199+
loadLibrary.invoke(BoxStore.getRelinker(), BoxStore.getContext(), OBJECTBOX_JNI, BoxStore.JNI_VERSION);
200200
}
201201
} catch (NoSuchMethodException e) {
202202
return false;

0 commit comments

Comments
 (0)