airbnb/lottie-android · error · EOFException

End of input

Error message

End of input

What it means

Thrown by nextNonWhitespace() (an internal method called by doPeek()) when the input source is exhausted while looking for the next meaningful character and throwOnEof is true. This is the fundamental 'unexpected end of JSON document' error — the parser needed more input to determine the next token type but none was available.

Source

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

            skipToEndOfLine();
            p = 0;
            continue;

          default:
            return c;
        }
      } else if (c == '#') {
        // Skip a # hash end-of-line comment. The JSON RFC doesn't specify this behaviour, but it's
        // required to parse existing documents.
        checkLenient();
        skipToEndOfLine();
        p = 0;
      } else {
        return c;
      }
    }
    if (throwOnEof) {
      throw new EOFException("End of input");
    } else {
      return -1;
    }
  }

  private void checkLenient() throws IOException {
    if (!lenient) {
      throw syntaxError("Use JsonReader.setLenient(true) to accept malformed JSON");
    }
  }

  /**
   * Advances the position until after the next newline character. If the line
   * is terminated by "\r\n", the '\n' must be consumed as whitespace by the
   * caller.
   */
  private void skipToEndOfLine() throws IOException {
    long index = source.indexOfElement(LINEFEED_OR_CARRIAGE_RETURN);

View on GitHub (pinned to 05ea92e903)

Solutions

  1. Verify the JSON input is non-empty and complete before passing to Lottie — check that it starts with '{' or '[' and ends with '}' or ']'
  2. Ensure the full file or stream is available: for assets, check the file exists and has content; for network, verify the response body
  3. If reading from a stream, buffer the entire input into a String or BufferedSource first, then validate before parsing
  4. Catch EOFException (or IOException) during composition loading and provide a fallback

Example fix

// before: passing an empty or truncated stream
// LottieCompositionFactory.fromJsonData("", cacheKey); // empty string

// after: validate input before loading
if (jsonData == null || jsonData.trim().isEmpty()) {
  Log.e(TAG, "Animation JSON is empty");
  showFallback();
  return;
}
LottieCompositionFactory.fromJsonData(jsonData, cacheKey);
Defensive patterns

Strategy: validation

Validate before calling

// Validate input is non-empty and looks like JSON before loading
boolean isValidLottieJson(String json) {
  if (json == null || json.trim().isEmpty()) return false;
  String trimmed = json.trim();
  return trimmed.startsWith("{") || trimmed.startsWith("[");
}

// Usage before loading:
if (!isValidLottieJson(jsonData)) {
  Log.e(TAG, "Invalid or empty Lottie JSON input");
  showFallback();
  return;
}
LottieCompositionFactory.fromJsonData(jsonData, cacheKey);

Try / catch

try {
  LottieCompositionFactory.fromJsonData(jsonData, cacheKey);
} catch (EOFException e) {
  Log.w(TAG, "Unexpected end of Lottie JSON input: " + e.getMessage());
  showFallbackAnimation();
} catch (IOException e) {
  Log.w(TAG, "I/O error reading Lottie JSON: " + e.getMessage());
  showFallbackAnimation();
}

Prevention

When it happens

Trigger: The reader's doPeek() calls nextNonWhitespace() to find the next non-whitespace character, but source.request() returns false (no more data) and throwOnEof is true. This occurs at the very start of parsing (empty input), or mid-document when the stream ends after whitespace (e.g., trailing whitespace at EOF after a complete value is fine, but EOF while expecting another token triggers this). The throw is at line 943.

Common situations: An empty or whitespace-only JSON input passed to Lottie. A truncated Lottie animation file. A network stream that closed prematurely. A file that was partially written. An input stream that threw during reading. This is often the first error seen when the input is fundamentally incomplete.

Related errors


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