{"record":{"id":"770771b05b678416","repo":"airbnb/epoxy","slug":"expected-this-to-be-a-variable-or-method-this","errorCode":null,"errorMessage":"Expected this to be a variable or method $this","messagePattern":"Expected this to be a variable or method \\$this","errorType":"exception","errorClass":"EpoxyProcessorException","httpStatus":null,"severity":"error","filePath":"epoxy-processor/src/main/java/com/airbnb/epoxy/processor/XProcessingUtils.kt","lineNumber":261,"sourceCode":"val XHasModifiers.javacModifiers: Set<Modifier>\n    get() {\n        return setOfNotNull(\n            if (isPublic()) Modifier.PUBLIC else null,\n            if (isProtected()) Modifier.PROTECTED else null,\n            if (isAbstract()) Modifier.ABSTRACT else null,\n            if (isPrivate()) Modifier.PRIVATE else null,\n            if (isStatic()) Modifier.STATIC else null,\n            if (isFinal()) Modifier.FINAL else null,\n            if (isTransient()) Modifier.TRANSIENT else null,\n        )\n    }\n\nval XElement.expectName: String\n    get() = when (this) {\n        is XVariableElement -> this.name\n        is XMethodElement -> this.name\n        is XTypeElement -> this.name\n        else -> throw EpoxyProcessorException(\n            \"Expected this to be a variable or method $this\",\n            element = this\n        )\n    }\n\nfun XType.isSubTypeOf(otherType: XType): Boolean {\n    // Using the normal \"isAssignableFrom\" on XType doesn't always work correctly or predictably\n    // with generics, so when we just want to check if something is a subclass without considering\n    // that this is the simplest approach.\n    // This is especially because we generally just use this to check class type hierarchies, not\n    // parameter/field types.\n    return otherType.rawType.isAssignableFrom(this)\n}\n\nfun XTypeElement.isSubTypeOf(otherType: XTypeElement): Boolean {\n    return type.isSubTypeOf(otherType.type)\n}\n","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/airbnb/epoxy/blob/e45bd3a61fe3a1f130e184f5b8dcf172ab99025a/epoxy-processor/src/main/java/com/airbnb/epoxy/processor/XProcessingUtils.kt#L243-L279","documentation":"expectName is an extension on XElement that extracts a name for variables, methods, and type elements. Any other XElement kind has no name to expect, so the getter throws EpoxyProcessorException (carrying the element) to fail annotation processing with a precise diagnostic instead of returning a bogus name.","triggerScenarios":"Processor code (e.g. attribute/hoisting logic) calls element.expectName on an XElement that is a variable, method, or type element — but encounters a different kind such as an executable's type parameter, a package element, or an unexpected modelin element subclass.","commonSituations":"New Epoxy model types/annotations whose processed elements aren't variables/methods/types (e.g. nested annotations); custom processor extensions calling expectName too broadly; library upgrades changing XProcessing element wrappers.","solutions":["Only call expectName after confirming the element kind (is XVariableElement / XMethodElement / XTypeElement).","Handle the element kind explicitly with a when and skip/derive names for unsupported kinds instead of calling expectName.","If triggered by a legit Epoxy feature, update epoxy-processor — the when in expectName may need the new element kind.","Use the element carried in EpoxyProcessorException to locate the offending declaration and fix the model code."],"exampleFix":"// before\nval name = element.expectName() // throws for unsupported kinds\n\n// after\nval name = when (element) {\n  is XVariableElement, is XMethodElement, is XTypeElement -> element.expectName\n  else -> return // or derive a name another way\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fun XElement.nameIfSupported(): String? = when (this) {\n  is XVariableElement -> this.name\n  is XMethodElement -> this.name\n  is XTypeElement -> this.name\n  else -> null\n}","tryCatchPattern":null,"preventionTips":["Narrow the element kind before calling expectName.","Keep expectName calls in code paths that provably handle only variables/methods/types.","When extending Epoxy's processor to new annotation targets, extend expectName's when branch."],"tags":["android","epoxy","annotation-processor","xprocessing","element-kind"],"backgroundTag":"type-mismatch","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"}