microg/GmsCore · error · NullPointerException
Cannot set null temp directory
Error message
Cannot set null temp directory
What it means
BitmapTeleporter.setTargetDirectory throws this NullPointerException when passed a null File. The directory is required because the teleporter writes the bitmap to a temp file in it during parceling; a null target would make the write path fail later, so it is rejected eagerly.
Source
Thrown at play-services-base/src/main/java/com/google/android/gms/common/data/BitmapTeleporter.java:90
ByteBuffer wrap = ByteBuffer.wrap(bArr);
Bitmap createBitmap = Bitmap.createBitmap(readInt, readInt2, valueOf);
createBitmap.copyPixelsFromBuffer(wrap);
this.targetBitmap = createBitmap;
this.isParceled = true;
} catch (IOException e) {
throw new IllegalStateException("Could not read from parcel file descriptor", e);
}
} catch (Throwable th) {
close(dataInputStream);
throw th;
}
}
return this.targetBitmap;
}
public final void setTargetDirectory(File file) {
if (file == null) {
throw new NullPointerException("Cannot set null temp directory");
}
this.targetDirectory = file;
}
private static void close(Closeable closeable) {
try {
closeable.close();
} catch (IOException e) {
Log.w("BitmapTeleporter", "Could not close stream", e);
}
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
CREATOR.writeToParcel(this, dest, flags);
}
public static final SafeParcelableCreatorAndWriter<BitmapTeleporter> CREATOR = findCreator(BitmapTeleporter.class);View on GitHub (pinned to 157c9d86ac)
Solutions
- Pass a guaranteed-writable directory: new File(context.getCacheDir(), "bmp_temp") is always non-null.
- If using external storage, null-check getExternalFilesDir(...) and fall back to cacheDir before calling setTargetDirectory.
- Validate the argument before the call in your own helper so the failure carries your message.
- Call setTargetDirectory early (before parceling) so misconfiguration surfaces during setup, not during transfer.
Example fix
// before teleporter.setTargetDirectory(context.getExternalFilesDir(null)); // may be null // after File dir = context.getExternalFilesDir(null); teleporter.setTargetDirectory(dir != null ? dir : new File(context.getCacheDir(), "bmp_temp"));
Defensive patterns
Strategy: validation
Validate before calling
File dir = context.getExternalFilesDir(null); if (dir == null) dir = new File(context.getCacheDir(), "bmp_temp"); if (!dir.exists()) dir.mkdirs(); teleporter.setTargetDirectory(dir);
Type guard
boolean isValidTargetDirectory(File f) {
return f != null && f.exists() ? f.isDirectory() : f != null;
} Try / catch
try {
teleporter.setTargetDirectory(dir);
} catch (NullPointerException e) {
teleporter.setTargetDirectory(new File(context.getCacheDir(), "bmp_temp"));
} Prevention
- Null-check getExternalFilesDir() results before use; it returns null when storage is unavailable.
- Default to internal cacheDir for temp bitmap storage.
- Call setTargetDirectory during setup, before any parceling.
- Wrap nullable directory providers in a small resolver helper.
When it happens
Trigger: Calling teleporter.setTargetDirectory(null) directly; passing a field or lookup result that is null, e.g. context.getExternalFilesDir(null) on storage-unavailable devices, or Environment.getExternalStorageDirectory() results that callers blindly forward.
Common situations: Devices with external storage unmounted where getExternalFilesDir returns null; initialization code running before storage is ready; refactors that replace a default directory with a nullable provider.
Related errors
- null reference
- Could not read from parcel file descriptor
- No service provided
- geofence can't be null.
- CameraUpdateFactory is not initialized
AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06).
Data as JSON: /api/errors/4942d80d719315c5.
Report an issue: GitHub.