microg/GmsCore · error · NullPointerException

null reference

Error message

null reference

What it means

BitmapTeleporter.createTargetBitmap throws this NullPointerException (message 'null reference', per the play-services-par style) when the bitmap has not been parceled but its ParcelFileDescriptor is null, so there is no pixel data source to read. The teleporter expects either an already-parceled bitmap or a valid file descriptor produced during parceling.

Source

Thrown at play-services-base/src/main/java/com/google/android/gms/common/data/BitmapTeleporter.java:61

        this.fileDescriptor = parcelFileDescriptor;
        this.status = status;
        this.targetBitmap = null;
        this.isParceled = false;
    }

    public BitmapTeleporter(Bitmap bitmap) {
        this.versionCode = 1;
        this.fileDescriptor = null;
        this.status = 0;
        this.targetBitmap = bitmap;
        this.isParceled = true;
    }

    public final Bitmap createTargetBitmap() {
        if (!this.isParceled) {
            ParcelFileDescriptor parcelFileDescriptor = this.fileDescriptor;
            if (parcelFileDescriptor == null) {
                throw new NullPointerException("null reference");
            }
            DataInputStream dataInputStream = new DataInputStream(new ParcelFileDescriptor.AutoCloseInputStream(parcelFileDescriptor));
            try {
                try {
                    byte[] bArr = new byte[dataInputStream.readInt()];
                    int readInt = dataInputStream.readInt();
                    int readInt2 = dataInputStream.readInt();
                    Bitmap.Config valueOf = Bitmap.Config.valueOf(dataInputStream.readUTF());
                    dataInputStream.read(bArr);
                    close(dataInputStream);
                    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);
                }

View on GitHub (pinned to 157c9d86ac)

Solutions

  1. Ensure the BitmapTeleporter goes through a Parcel/Parcelable round-trip (write then read) before calling createTargetBitmap(), which populates the file descriptor.
  2. Check the bitmapper source: call teleportBitmap()/writeToParcel properly with a valid temp directory via setTargetDirectory before use.
  3. Guard the call: only invoke createTargetBitmap() when the descriptor exists (or when the instance came from a valid parcel read).
  4. Catch NullPointerException and surface a clear 'bitmap was never parceled' error in your code.

Example fix

// before
Bitmap bmp = teleporter.createTargetBitmap(); // NPE if never parceled

// after
if (teleporter.isParceled() || teleporterHasDescriptor(teleporter)) {
    Bitmap bmp = teleporter.createTargetBitmap();
} else {
    Bitmap bmp = originalBitmap; // use in-memory source instead
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (teleporter == null || (!teleporter.isParceled && !hasDescriptor)) {
    Log.w(TAG, "BitmapTeleporter has no parceled data");
    return null;
}

Type guard

boolean isReadable(BitmapTeleporter t) {
    return t.isParceled || t.getFileDescriptorSafe() != null; // only via Parcelable round-trip
}

Try / catch

try {
    return teleporter.createTargetBitmap();
} catch (NullPointerException e) {
    Log.w(TAG, "BitmapTeleporter was never parceled", e);
    return fallbackBitmap;
}

Prevention

When it happens

Trigger: Calling createTargetBitmap() on a BitmapTeleporter that was never written to a Parcel (so fileDescriptor was never populated); manually constructing an empty BitmapTeleporter and trying to read the bitmap; calling it twice on a fresh instance after close/stream already consumed state in a way that nulled the descriptor.

Common situations: Deserializing an incompletely transferred BitmapTeleporter; misusing the class by creating it directly instead of obtaining it from a Parcelable round-trip; error paths where parceling failed silently and the descriptor stayed null.

Related errors


AI-assisted analysis of microg/GmsCore@157c9d86ac (2026-09-06). Data as JSON: /api/errors/9545be66dbe85f30. Report an issue: GitHub.