GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Builder: store context.getApplicationContext to prevent leaks. · mimoccc/objectbox-java@d11c4a4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • objectbox-java/src/main/java/io/objectbox
    • BoxStoreBuilder.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java‎

Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/BoxStoreBuilder.java
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public BoxStoreBuilder androidContext(Object context) {
178178
if (context == null) {
179179
throw new NullPointerException("Context may not be null");
180180
}
181-
this.context = context;
181+
this.context = getApplicationContext(context);
182182

183183
File baseDir = getAndroidBaseDir(context);
184184
if (!baseDir.exists()) {
@@ -195,6 +195,14 @@ public BoxStoreBuilder androidContext(Object context) {
195195
return this;
196196
}
197197

198+
private Object getApplicationContext(Object context) {
199+
try {
200+
return context.getClass().getMethod("getApplicationContext").invoke(context);
201+
} catch (ReflectiveOperationException e) {
202+
throw new RuntimeException("context must be a valid Android Context", e);
203+
}
204+
}
205+
198206
/**
199207
* Pass a custom ReLinkerInstance, for example {@code ReLinker.log(logger)} to use for loading the native library
200208
* on Android devices. Note that setting {@link #androidContext(Object)} is required for ReLinker to work.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.