airbnb/lottie-android · error · NullPointerException

source == null

Error message

source == null

What it means

The JsonUtf8Reader constructor takes a BufferedSource (Okio) and immediately checks for null. If null, it throws NullPointerException. This is a programmer-error guard — the reader cannot function without a data source. This exception should never reach end users; it indicates a bug in calling code.

Source

Thrown at lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java:102

   */
  private long peekedLong;

  /**
   * The number of characters in a peeked number literal.
   */
  private int peekedNumberLength;

  /**
   * A peeked string that should be parsed on the next double, long or string.
   * This is populated before a numeric value is parsed and used if that parsing
   * fails.
   */
  private @Nullable
  String peekedString;

  JsonUtf8Reader(BufferedSource source) {
    if (source == null) {
      throw new NullPointerException("source == null");
    }
    this.source = source;
    // Don't use source.getBuffer(). Because android studio use old version okio instead of your own okio.
    this.buffer = source.buffer();
    pushScope(JsonScope.EMPTY_DOCUMENT);
  }


  @Override public void beginArray() throws IOException {
    int p = peeked;
    if (p == PEEKED_NONE) {
      p = doPeek();
    }
    if (p == PEEKED_BEGIN_ARRAY) {
      pushScope(JsonScope.EMPTY_ARRAY);
      pathIndices[stackSize - 1] = 0;
      peeked = PEEKED_NONE;
    } else {

View on GitHub (pinned to 05ea92e903)

Solutions

  1. Check that the animation file/asset exists and the path is correct before attempting to load it.
  2. Null-check the InputStream/BufferedSource before passing it to LottieAnimationView.setAnimation() or the parser.
  3. Verify asset filenames match exactly (case-sensitive on Android) and the file is in the correct assets/ directory.

Example fix

// before
InputStream stream = getAssets().open(name); // may throw or return null
LottieCompositionFactory.fromInputStream(stream); // NPE if stream is null

// after
InputStream stream = getAssets().open(name);
if (stream == null) {
    Log.e(TAG, "Animation asset not found: " + name);
    return;
}
LottieCompositionFactory.fromInputStream(stream);
Defensive patterns

Strategy: validation

Validate before calling

// Null-check the source before loading
InputStream stream = null;
try {
    stream = context.getAssets().open(name);
} catch (IOException e) {
    // asset missing
}
if (stream == null) {
    // do not pass to Lottie
}

Prevention

When it happens

Trigger: Constructing a JsonUtf8Reader (typically via JsonReader.of() or the Lottie parser internals) with a null BufferedSource argument. This happens when the input stream, file, or asset that should provide JSON is null before being wrapped.

Common situations: Loading a Lottie animation from an asset/resource that doesn't exist (getAssets().open() returns null or is wrapped incorrectly); passing a null InputStream to the parser; broken asset path in the app; proguard/R8 stripping causing a null source to be passed unexpectedly.

Related errors


AI-assisted analysis of airbnb/lottie-android@05ea92e903 (2026-08-14). Data as JSON: /api/errors/8f2b92d04e2920cf. Report an issue: GitHub.