{"record":{"id":"9549e3fe3b487047","repo":"airbnb/epoxy","slug":"model-is-not-added-model","errorCode":null,"errorMessage":"Model is not added: {model}","messagePattern":"Model is not added: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyAdapter.java","lineNumber":342,"sourceCode":"   * Hides all models currently located after the given model in the {@link #models} list.\n   *\n   * @param model The model after which to hide. It must exist in the {@link #models} list.\n   */\n  protected void hideAllAfterModel(EpoxyModel<?> model) {\n    hideModels(getAllModelsAfter(model));\n  }\n\n  /**\n   * Returns a sub list of all items in {@link #models} that occur after the given model. This list\n   * is backed by the original models list, any changes to the returned list will be reflected in\n   * the original {@link #models} list.\n   *\n   * @param model Must exist in {@link #models}.\n   */\n  protected List<EpoxyModel<?>> getAllModelsAfter(EpoxyModel<?> model) {\n    int index = getModelPosition(model);\n    if (index == -1) {\n      throw new IllegalStateException(\"Model is not added: \" + model);\n    }\n    return models.subList(index + 1, models.size());\n  }\n\n  /**\n   * We pause the list's notifications when we modify models internally, since we already do the\n   * proper adapter notifications for those modifications. By pausing these list notifications we\n   * prevent the differ having to do work to track them.\n   */\n  private void pauseModelListNotifications() {\n    ((ModelList) models).pauseNotifications();\n  }\n\n  private void resumeModelListNotifications() {\n    ((ModelList) models).resumeNotifications();\n  }\n}\n","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/airbnb/epoxy/blob/e45bd3a61fe3a1f130e184f5b8dcf172ab99025a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyAdapter.java#L324-L360","documentation":"getAllModelsAfter(model) requires the given model to exist in the models list (documented via @param model Must exist in {@link #models}). When getModelPosition(model) returns -1 the sublist cannot be computed, so an IllegalStateException \"Model is not added\" is thrown.","triggerScenarios":"Calling getAllModelsAfter (directly, or via hideAllAfterModel/modelsToRemove) with a model that is not currently in the adapter's models list.","commonSituations":"hideAllAfterModel on a model that was conditionally not added; a stale model reference after a clearModels(); diffing-based updates removing the anchor before the helper runs.","solutions":["Verify the anchor model is present (getModelPosition(model) != -1) before calling","Ensure the anchor model is added unconditionally or guard the call behind the same condition that adds it","Re-acquire the model reference from the adapter instead of holding stale instances across updates"],"exampleFix":"// before\nadapter.hideAllAfterModel(myHeader);\n// after\nif (adapter.getModelPosition(myHeader) != -1) {\n  adapter.hideAllAfterModel(myHeader);\n}","handlingStrategy":"validation","validationCode":"if (adapter.getModelPosition(model) != -1) { List<EpoxyModel<?>> after = adapter.getAllModelsAfter(model); }","typeGuard":null,"tryCatchPattern":"try { adapter.hideAllAfterModel(model); } catch (IllegalStateException e) { /* anchor missing; skip or rebuild list */ }","preventionTips":["Only call hideAllAfterModel/getAllModelsAfter with models added unconditionally","Re-fetch model instances from the adapter after list rebuilds instead of caching"],"tags":["android","epoxy","model-not-added","illegal-state"],"backgroundTag":"entity-not-found","analyzedSha":"e45bd3a61fe3a1f130e184f5b8dcf172ab99025a","analyzedAt":"2026-09-13T03:24:16.052Z","contentChangedAt":"2026-09-13T03:24:16.052Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}