{"record":{"id":"ba093f4cd3fae25a","repo":"airbnb/lottie-android","slug":"expected-an-int-but-was-at-path","errorCode":null,"errorMessage":"Expected an int but was {} at path {}","messagePattern":"Expected an int but was (.+?) at path (.+?)","errorType":"exception","errorClass":"JsonDataException","httpStatus":null,"severity":"error","filePath":"lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java","lineNumber":778,"sourceCode":"    }\n  }\n\n  private void skipUnquotedValue() throws IOException {\n    long i = source.indexOfElement(UNQUOTED_STRING_TERMINALS);\n    buffer.skip(i != -1L ? i : buffer.size());\n  }\n\n  @Override public int nextInt() throws IOException {\n    int p = peeked;\n    if (p == PEEKED_NONE) {\n      p = doPeek();\n    }\n\n    int result;\n    if (p == PEEKED_LONG) {\n      result = (int) peekedLong;\n      if (peekedLong != result) { // Make sure no precision was lost casting to 'int'.\n        throw new JsonDataException(\"Expected an int but was \" + peekedLong\n            + \" at path \" + getPath());\n      }\n      peeked = PEEKED_NONE;\n      pathIndices[stackSize - 1]++;\n      return result;\n    }\n\n    if (p == PEEKED_NUMBER) {\n      peekedString = buffer.readUtf8(peekedNumberLength);\n    } else if (p == PEEKED_DOUBLE_QUOTED || p == PEEKED_SINGLE_QUOTED) {\n      peekedString = p == PEEKED_DOUBLE_QUOTED\n          ? nextQuotedValue(DOUBLE_QUOTE_OR_SLASH)\n          : nextQuotedValue(SINGLE_QUOTE_OR_SLASH);\n      try {\n        result = Integer.parseInt(peekedString);\n        peeked = PEEKED_NONE;\n        pathIndices[stackSize - 1]++;\n        return result;","sourceCodeStart":760,"sourceCodeEnd":796,"githubUrl":"https://github.com/airbnb/lottie-android/blob/05ea92e90381eb8a8ae06855ea2b74f322bebbec/lottie/src/main/java/com/airbnb/lottie/parser/moshi/JsonUtf8Reader.java#L760-L796","documentation":"Thrown by nextInt() when the peeked token was a PEEKED_LONG — a numeric literal that fit in a long — but casting it to int caused precision loss. This means the JSON number was outside the 32-bit signed integer range (-2,147,483,648 to 2,147,483,647). The check `peekedLong != result` at line 777 detects that the narrowing cast lost data.","triggerScenarios":"nextInt() is called on a JSON value that is a valid number but exceeds Integer.MAX_VALUE or is below Integer.MIN_VALUE. For example, a frame number, blend mode constant, or integer property that is unexpectedly large (e.g., 3000000000, or a timestamp in milliseconds). The throw occurs at JsonUtf8Reader.java:778.","commonSituations":"A Lottie JSON integer field contains an unexpectedly large value due to a Bodymovin plugin bug or misconfigured expression. A field that should be a small enum or index contains a garbage large number from a corrupted file. A version change in the export format using long timestamps or IDs where the Lottie parser expects an int.","solutions":["Inspect the JSON at the reported path and correct the oversized integer to a valid int-range value","Re-export the animation from After Effects with a compatible Bodymovin version","If consuming untrusted JSON, pre-validate integer fields against Integer range before handing to Lottie","Catch the JsonDataException during composition loading to show a fallback instead of crashing"],"exampleFix":"// before: {\"ind\": 9999999999}  // asset index exceeds int range\n// after:  {\"ind\": 0}","handlingStrategy":"validation","validationCode":"// Check integer fields are within int range\nboolean isSafeInt(long value) {\n  return value >= Integer.MIN_VALUE && value <= Integer.MAX_VALUE;\n}\n\n// During JSON pre-validation:\nvoid validateIntFields(org.json.JSONObject obj, String[] intFields) throws Exception {\n  for (String field : intFields) {\n    if (obj.has(field) && obj.get(field) instanceof Long) {\n      long val = obj.getLong(field);\n      if (!isSafeInt(val)) throw new IllegalStateException(field + \" exceeds int range: \" + val);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  LottieCompositionFactory.fromJsonData(jsonData, cacheKey);\n} catch (JsonDataException e) {\n  if (e.getMessage().contains(\"Expected an int\")) {\n    Log.w(TAG, \"Integer overflow in Lottie JSON: \" + e.getMessage());\n  }\n  showFallbackAnimation();\n}","preventionTips":["Validate integer-range fields in the JSON before loading","Re-export from After Effects to fix corrupt integer values","Log the reported value and path to trace which field overflows"],"tags":["json-parsing","moshi","lottie","integer-overflow"],"backgroundTag":null,"analyzedSha":"05ea92e90381eb8a8ae06855ea2b74f322bebbec","analyzedAt":"2026-08-14T00:51:35.636Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}