Skip to content

Commit 1e607be

Browse files
committed
getAndroidFilesDir: fail fast if dir does not exist, etc.
1 parent 8ccbbf4 commit 1e607be

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ public BoxStoreBuilder androidContext(Object context) {
151151
File filesDir = getAndroidFilesDir(context);
152152
File baseDir = new File(filesDir, "objectbox");
153153
if (!baseDir.exists()) {
154-
boolean ok = baseDir.mkdirs();
155-
if (!ok) {
156-
System.err.print("Could not create base dir");
154+
baseDir.mkdir();
155+
if (!baseDir.exists()) { // check baseDir.exists() because of potential concurrent processes
156+
throw new RuntimeException("Could not init Android base dir at " + baseDir.getAbsolutePath());
157157
}
158158
}
159-
if (!baseDir.exists() || !baseDir.isDirectory()) {
160-
throw new RuntimeException("Could not init Android base dir at " + baseDir.getAbsolutePath());
159+
if (!baseDir.isDirectory()) {
160+
throw new RuntimeException("Android base dir is not a dir: " + baseDir.getAbsolutePath());
161161
}
162162
baseDirectory = baseDir;
163163
android = true;
@@ -182,6 +182,9 @@ private File getAndroidFilesDir(Object context) {
182182
if (filesDir == null) {
183183
throw new IllegalStateException("Android files dir is null");
184184
}
185+
if (!filesDir.exists()) {
186+
throw new IllegalStateException("Android files dir does not exist");
187+
}
185188
return filesDir;
186189
}
187190

0 commit comments

Comments
 (0)