{"record":{"id":"7ab8ec559d8ed2f9","repo":"airbnb/epoxy","slug":"models-were-set-with-setmodels-they-can-not-be-rebuilt","errorCode":null,"errorMessage":"Models were set with #setModels, they can not be rebuilt.","messagePattern":"Models were set with #setModels, they can not be rebuilt\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyRecyclerView.kt","lineNumber":539,"sourceCode":"         */\n        fun buildModels(controller: EpoxyController)\n    }\n\n    /**\n     * Request that the currently set EpoxyController has its models rebuilt. You can use this to\n     * avoid saving your controller as a field.\n     *\n     * You cannot use this if your controller is a [TypedEpoxyController] or if you set\n     * models via [setModels]. In that case you must set data directly on the\n     * controller or set models again.\n     */\n    fun requestModelBuild() {\n        if (epoxyController == null) {\n            throw IllegalStateException(\"A controller must be set before requesting a model build.\")\n        }\n\n        if (epoxyController is SimpleEpoxyController) {\n            throw IllegalStateException(\"Models were set with #setModels, they can not be rebuilt.\")\n        }\n\n        epoxyController!!.requestModelBuild()\n    }\n\n    /**\n     * Clear the currently set EpoxyController or Adapter as well as any models that are displayed.\n     *\n     * Any pending requests to the EpoxyController to build models are canceled.\n     *\n     * Any existing child views are recycled to the view pool.\n     */\n    open fun clear() {\n        // The controller is cleared so the next time models are set we can create a fresh one.\n        epoxyController?.cancelPendingModelBuild()\n        epoxyController = null\n\n        // We use swapAdapter instead of setAdapter so that the view pool is not cleared.","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/airbnb/epoxy/blob/e45bd3a61fe3a1f130e184f5b8dcf172ab99025a/epoxy-adapter/src/main/java/com/airbnb/epoxy/EpoxyRecyclerView.kt#L521-L557","documentation":"EpoxyRecyclerView.requestModelBuild() cannot rebuild models when the controller is a SimpleEpoxyController created internally by setModels — its models were supplied explicitly and there is no build callback to re-run. Attempting this throws this IllegalStateException.","triggerScenarios":"Calling recyclerView.requestModelBuild() after models were set via recyclerView.setModels(...) (or modelsWithConstructors), which internally uses a SimpleEpoxyController.","commonSituations":"Mixing setModels usage with requestModelBuild for refresh; assuming requestModelBuild works universally like with controller-based setups.","solutions":["Re-call recyclerView.setModels(newModels) with a freshly built list","Switch to recyclerView.withModels { ... } so requestModelBuild has a rebuild callback","If using a TypedEpoxyController, call setData on the controller instead"],"exampleFix":"// before\nrecyclerView.setModels(models);\nrecyclerView.requestModelBuild(); // throws\n// after\nrecyclerView.setModels(buildModelList()); // rebuild by re-setting models","handlingStrategy":"validation","validationCode":"val controller = recyclerView.epoxyController\nif (controller != null && controller !is SimpleEpoxyController) recyclerView.requestModelBuild() else recyclerView.setModels(buildModelList())","typeGuard":"fun canRebuild(rv: EpoxyRecyclerView) = rv.epoxyController != null && rv.epoxyController !is SimpleEpoxyController","tryCatchPattern":"try { recyclerView.requestModelBuild() } catch (e: IllegalStateException) { recyclerView.setModels(buildModelList()) }","preventionTips":["Pick one model-supply style (withModels vs setModels) per RecyclerView","Track whether setModels was used; refresh via setModels only","Prefer controller-based setup for refreshable lists"],"tags":["android","epoxy","illegal-state","api-misuse"],"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"}