Quantcast
Channel: Mobile - Couchbase Forums
Viewing all articles
Browse latest Browse all 1117

CouchbaseLite.init() IllegalStateException: Tmp dir root is null

$
0
0

We have a user that experiences this crash repeatedly:

Caused by java.lang.IllegalStateException: Tmp dir root is null
       at com.couchbase.lite.internal.CouchbaseLiteInternal.makeTmpPath(CouchbaseLiteInternal.java:152)
       at com.couchbase.lite.internal.CouchbaseLiteInternal.initDirectories(CouchbaseLiteInternal.java:206)
       at com.couchbase.lite.internal.CouchbaseLiteInternal.init(CouchbaseLiteInternal.java:94)
       at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:53)
       at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:35)

Looking at the code:

@NonNull
public static String makeTmpPath(@Nullable String rootDir) {
    requireInit("Can't create tmp dir path");
    final File dir = (rootDir != null)
            ? new File(rootDir, TEMP_DIR_NAME)
            : getContext().getExternalFilesDir(TEMP_DIR_NAME);
    if (dir == null) { throw new IllegalStateException("Tmp dir root is null"); }
    return verifyDir(dir);
}

getExternalFilesDir() is documented “May return null if shared storage is not currently available.” I’d expect there should be a proper fallback to be able to create a tmp directory on internal storage if external storage is unavailable instead of crashing the app in this case. Or possibly just create it on internal storage in the first place, which is always available.

For example:

@NonNull
public static String makeTmpPath(@Nullable String rootDir) {
    requireInit("Can't create tmp dir path");
    File dir = (rootDir != null)
            ? new File(rootDir, TEMP_DIR_NAME)
            : getContext().getExternalFilesDir(TEMP_DIR_NAME);
    if (dir == null) {
        dir = getContext().getDir(TEMP_DIR_NAME, Context.MODE_PRIVATE);
    }
    return verifyDir(dir);
}

7 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 1117

Trending Articles