{"record":{"id":"33fe475499aec97e","repo":"airbnb/epoxy","slug":"0-is-an-invalid-value-for-required-strings","errorCode":null,"errorMessage":"0 is an invalid value for required strings.","messagePattern":"0 is an invalid value for required strings\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"epoxy-adapter/src/main/java/com/airbnb/epoxy/StringAttributeData.java","lineNumber":71,"sourceCode":"    if (stringRes != 0) {\n      this.stringRes = stringRes;\n      this.formatArgs = formatArgs;\n      string = null;\n      pluralRes = 0;\n    } else {\n      handleInvalidStringRes();\n    }\n  }\n\n  private void handleInvalidStringRes() {\n    if (hasDefault) {\n      if (defaultStringRes != 0) {\n        setValue(defaultStringRes);\n      } else {\n        setValue(defaultString);\n      }\n    } else {\n      throw new IllegalArgumentException(\"0 is an invalid value for required strings.\");\n    }\n  }\n\n  public void setValue(@PluralsRes int pluralRes, int quantity, @Nullable Object[] formatArgs) {\n    if (pluralRes != 0) {\n      this.pluralRes = pluralRes;\n      this.quantity = quantity;\n      this.formatArgs = formatArgs;\n      string = null;\n      stringRes = 0;\n    } else {\n      handleInvalidStringRes();\n    }\n  }\n\n  public CharSequence toString(Context context) {\n    if (pluralRes != 0) {\n      if (formatArgs != null) {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/airbnb/epoxy/blob/e45bd3a61fe3a1f130e184f5b8dcf172ab99025a/epoxy-adapter/src/main/java/com/airbnb/epoxy/StringAttributeData.java#L53-L89","documentation":"StringAttributeData validates that string resources passed to an Epoxy model attribute are non-zero. `0` is the Android framework's sentinel for 'no resource' and `Resources.getString(0)` would fail; Epoxy rejects it eagerly with `IllegalArgumentException` instead of letting a confusing NotFound crash happen later. Required string attributes must always receive a valid, non-zero resource ID or a literal string.","triggerScenarios":"Calling `setValue(0)` on a required string attribute — e.g. `.title(0)` or `.text(someResId)` where `someResId` defaulted to 0. Also happens when a generated model setter receives an uninitialized `@StringRes` field, or when `defaultStringRes` was left at 0 and the fallback path runs `setValue(0)`.","commonSituations":"A developer stores a resource ID in a field initialized to 0 and forgets to assign it; a server response lacks a value and the code passes 0 as a placeholder; a configurable attr is read from a config/bundle where the key is missing so `getInt` returns 0.","solutions":["Pass a real, non-zero `@StringRes` resource ID (e.g. `R.string.title`) to the attribute.","If the value may be absent, make the attribute optional with `.title(null)` via a nullable/text setter instead of passing 0.","Set a literal string with `.title(\"Some text\")` when you don't have a resource.","Check upstream defaults: initialize resource-ID fields to `R.string.empty` or `View.NO_ID` and guard before calling the setter.","Verify the failing resource actually exists in the right module so it isn't resolving to 0."],"exampleFix":"// before\nint titleRes = 0; // never assigned\nmodel.title(titleRes); // throws\n\n// after\nif (titleRes != 0) {\n  model.title(titleRes);\n} else {\n  model.title(R.string.default_title);\n}","handlingStrategy":"validation","validationCode":"// Guard before calling a required string attribute\nif (titleResId != 0) {\n  model.title(titleResId);\n} else {\n  model.title(R.string.default_title); // or model.title(null) if optional\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never initialize @StringRes/@PluralsRes fields to 0; use a real default resource.","Prefer optional/nullable attribute setters when the value can be absent.","Check defaults read from bundles/intents — getInt returns 0 for missing keys.","Consider storing `View.NO_ID` and branching explicitly instead of passing it through."],"tags":["android","epoxy","resources","argument-validation"],"backgroundTag":"invalid-argument-value","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"}