{"record":{"id":"240ed440bd892931","repo":"airbnb/epoxy","slug":"failed-to-create-regex-for-resource-reference","errorCode":null,"errorMessage":"Failed to create regex for resource reference '$annotationReferencePrefix'","messagePattern":"Failed to create regex for resource reference '\\$annotationReferencePrefix'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"epoxy-processor/src/main/java/com/airbnb/epoxy/processor/resourcescanning/KspResourceScanner.kt","lineNumber":431,"sourceCode":"            expression.getReferencedNameAsName()\n        } else {\n            null\n        }\n    }\n\n    companion object {\n        internal fun findMatchingImportPackage(\n            importedNames: List<String>,\n            annotationReference: String,\n            annotationReferencePrefix: String,\n            packageName: String\n        ): ImportMatch {\n            // Match something like \"com.airbnb.paris.test.R2 as typeAliasedR\"\n            val typeAliasRegex = try {\n                Regex(\"(.*)\\\\s+as\\\\s+$annotationReferencePrefix\\$\")\n            } catch (e: PatternSyntaxException) {\n                // Provide more information in this case so we can better debug https://github.com/airbnb/epoxy/issues/1265\n                throw IllegalStateException(\"Failed to create regex for resource reference '$annotationReferencePrefix'\", e)\n            }\n\n            return importedNames.firstNotNullOfOrNull { importedName ->\n\n                when {\n                    importedName.endsWith(\".$annotationReferencePrefix\") -> {\n                        // import com.example.R\n                        // R.layout.my_layout -> R\n                        Normal(\n                            referenceImportPrefix = importedName.substringBeforeLast(\".$annotationReferencePrefix\"),\n                            annotationReference = annotationReference\n                        )\n                    }\n                    importedName.contains(typeAliasRegex) -> {\n                        typeAliasRegex.find(importedName)?.groupValues?.getOrNull(1)\n                            ?.let { import ->\n                                TypeAlias(import, annotationReferencePrefix, annotationReference)\n                            }","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/airbnb/epoxy/blob/e45bd3a61fe3a1f130e184f5b8dcf172ab99025a/epoxy-processor/src/main/java/com/airbnb/epoxy/processor/resourcescanning/KspResourceScanner.kt#L413-L449","documentation":"This IllegalStateException is thrown when the Epoxy annotation processor fails to compile a regex used to match import statements containing an R/R2 class reference (e.g. 'com.airbnb.paris.test.R2 as typeAliasedR'). The regex embeds the annotation reference prefix directly into the pattern, so a prefix containing regex metacharacters or malformed escape sequences causes PatternSyntaxException, which is rewrapped with the offending prefix to aid debugging of airbnb/epoxy#1265.","triggerScenarios":"findMatchingImportPackage builds Regex(\"(.*)\\\\s+as\\\\s+$annotationReferencePrefix$\") and the annotationReferencePrefix value produces an invalid regex — e.g. it contains characters like '(', '[', '*' or a bad escape sequence. Reached via findMatchingImportPackageJava or findMatchingImportPackageKt when scanning Java/Kotlin imports for resource references.","commonSituations":"Unusual R class naming or generated R/R2 package fragments containing characters that are regex metacharacters (dashes, dots-adjacent brackets in package fragments, custom resource name prefixes), typically after Gradle namespace or resource prefix configuration changes. Historically seen with Kotlin type-aliased imports (issue #1265).","solutions":["Inspect the reported '$annotationReferencePrefix' value in the message and find which character makes it an invalid regex; rename/fix the resource prefix or package fragment that produced it","Update Epoxy to the latest processor version, where regex metacharacters in the prefix may be escaped or the underlying #1265 bug is fixed","As a workaround, avoid type-aliased R imports ('import com.foo.R as R') in classes annotated with Epoxy model annotations, or import the R class directly","File/check the epoxy issue tracker (#1265) if the prefix looks valid — the scanner may be passing the wrong string"],"exampleFix":"// before (in a build.gradle.kts with a resource prefix that leaks into the reference)\nandroidResources { prefix = \"my-app_\" }\n// after\nandroidResources { prefix = \"my_app_\" }\n// or in model code, avoid: import com.airbnb.epoxy.R as EpoxyR","handlingStrategy":"validation","validationCode":"// before running the processor, sanity-check your resource prefix / R imports\nval risky = Regex.containingMetaChars // conceptually:\nfun prefixIsRegexSafe(prefix: String) =\n    prefix.none { it in \"\\\\()[]{}*+?|^$.\" }\nif (!prefixIsRegexSafe(myResourcePrefix)) {\n    throw IllegalArgumentException(\"Resource prefix '$myResourcePrefix' contains regex metacharacters\")\n}","typeGuard":"fun isRegexSafe(s: String): Boolean =\n    runCatching { Regex(\"(.*)\\\\s+as\\\\s+\" + Regex.escape(s) + \"$\") }.isSuccess","tryCatchPattern":null,"preventionTips":["Keep R class / resource prefixes limited to letters, digits and underscores","Avoid type-aliased imports of R/R2 classes in Epoxy-annotated classes","Pin a processor version where the #1265 fix is included and keep it updated"],"tags":["regex","annotation-processor","kotlin","epoxy"],"backgroundTag":"invalid-regex-pattern","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"}