{"record":{"id":"cb74c2ed70db3cee","repo":"airbnb/epoxy","slug":"you-cannot-hide-a-model-in-an-epoxycontroller-use-addif-to","errorCode":null,"errorMessage":"You cannot hide a model in an EpoxyController. Use `addIf` to conditionally add a model instead.","messagePattern":"You cannot hide a model in an EpoxyController\\. Use `addIf` to conditionally add a model instead\\.","errorType":"exception","errorClass":"IllegalEpoxyUsage","httpStatus":null,"severity":"error","filePath":"epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyController.java","lineNumber":508,"sourceCode":"      add(model);\n    }\n  }\n\n  /**\n   * Method to actually add the model to the list being built. Should be called after all\n   * validations are done.\n   */\n  void addInternal(EpoxyModel<?> modelToAdd) {\n    assertIsBuildingModels();\n\n    if (modelToAdd.hasDefaultId()) {\n      throw new IllegalEpoxyUsage(\n          \"You must set an id on a model before adding it. Use the @AutoModel annotation if you \"\n              + \"want an id to be automatically generated for you.\");\n    }\n\n    if (!modelToAdd.isShown()) {\n      throw new IllegalEpoxyUsage(\n          \"You cannot hide a model in an EpoxyController. Use `addIf` to conditionally add a \"\n              + \"model instead.\");\n    }\n\n    // The model being added may not have been staged if it wasn't mutated before it was added.\n    // In that case we may have a previously staged model that still needs to be added.\n    clearModelFromStaging(modelToAdd);\n    modelToAdd.controllerToStageTo = null;\n    modelsBeingBuilt.add(modelToAdd);\n  }\n\n  /**\n   * Staging models allows them to be implicitly added after the user finishes modifying them. This\n   * means that if a user has modified a model, and then moves on to modifying a different model,\n   * the first model is automatically added as soon as the second model is modified.\n   * <p>\n   * There are some edge cases for handling models that are added without modification, or models\n   * that are modified but then fail an `addIf` check.","sourceCodeStart":490,"sourceCodeEnd":526,"githubUrl":"https://github.com/airbnb/epoxy/blob/e45bd3a61fe3a1f130e184f5b8dcf172ab99025a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyController.java#L490-L526","documentation":"Models added through an EpoxyController must be shown; hiding (show(false)) is unsupported because the controller's declarative list should simply omit models that shouldn't appear. addInternal throws IllegalEpoxyUsage, directing you to addIf/addUnless for conditional addition.","triggerScenarios":"Calling .show(false) (or hide()) on a model and then addTo(this)/addInternal inside buildModels().","commonSituations":"Porting adapter code where hide() was allowed; conditionally hiding a model based on a boolean instead of conditionally adding it; a helper method that sets show(false) for empty data before adding.","solutions":["Remove .show(false)/hide() and add the model only when its condition is true","Use addIf(boolean, model) or model.addIf(condition, this) for conditional addition","If default-shown logic hides models, restructure so the model is constructed only when it should appear"],"exampleFix":"// before\nnew FooterModel_().id(2).show(false).addTo(this); // crash\n// after\nnew FooterModel_().id(2).addIf(showFooter, this);","handlingStrategy":"validation","validationCode":"if (!model.isShown()) { /* don't add; use addIf instead */ } else { model.addTo(controller); }","typeGuard":null,"tryCatchPattern":"try { model.addTo(controller); } catch (IllegalEpoxyUsage e) { model.addIf(shouldBeShown, controller); }","preventionTips":["Never call show(false)/hide() on models added via a controller; use addIf/addUnless","Restructure ported adapter code so conditional visibility becomes conditional addition"],"tags":["android","epoxy","hidden-model","illegal-usage"],"backgroundTag":"unsupported-operation","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"}