{"record":{"id":"9f4ce459df31101c","repo":"material-components/material-components-android","slug":"boxbackgroundmode-is-illegal-only-boxbackgro","errorCode":null,"errorMessage":"> boxBackgroundMode < is illegal; only @BoxBackgroundMode constants are supported.","messagePattern":"> boxBackgroundMode < is illegal; only @BoxBackgroundMode constants are supported\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/textfield/TextInputLayout.java","lineNumber":842,"sourceCode":"        boxUnderlineDefault = new MaterialShapeDrawable();\n        boxUnderlineFocused = new MaterialShapeDrawable();\n        break;\n      case BOX_BACKGROUND_OUTLINE:\n        if (hintEnabled && !(boxBackground instanceof CutoutDrawable)) {\n          boxBackground = CutoutDrawable.create(shapeAppearanceModel);\n        } else {\n          boxBackground = new MaterialShapeDrawable(shapeAppearanceModel);\n        }\n        boxUnderlineDefault = null;\n        boxUnderlineFocused = null;\n        break;\n      case BOX_BACKGROUND_NONE:\n        boxBackground = null;\n        boxUnderlineDefault = null;\n        boxUnderlineFocused = null;\n        break;\n      default:\n        throw new IllegalArgumentException(\n            boxBackgroundMode + \" is illegal; only @BoxBackgroundMode constants are supported.\");\n    }\n  }\n\n  void updateEditTextBoxBackgroundIfNeeded() {\n    if (editText == null\n        || boxBackground == null\n        // Only set boxBackground when edit text doesn't provide its own background.\n        || (!boxBackgroundApplied && editText.getBackground() != null)\n        || boxBackgroundMode == BOX_BACKGROUND_NONE) {\n      return;\n    }\n    updateEditTextBoxBackground();\n    boxBackgroundApplied = true;\n  }\n\n  private void updateEditTextBoxBackground() {\n    Drawable editTextBoxBackground = getEditTextBoxBackground();","sourceCodeStart":824,"sourceCodeEnd":860,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/textfield/TextInputLayout.java#L824-L860","documentation":"TextInputLayout's box-background setup switches over the @BoxBackgroundMode IntDef constants (FILLED, OUTLINE, NONE) to build the matching MaterialShapeDrawable underline/background. Any other int reaches default and throws IllegalArgumentException stating only BoxBackgroundMode constants are supported.","triggerScenarios":"Calling setBoxBackgroundMode(arbitraryInt) with a value outside BOX_BACKGROUND_NONE/FILLED/OUTLINE; invalid app:boxBackgroundMode in XML.","commonSituations":"Passing an unvalidated persisted mode; using a constant that exists only in a different Material version; arithmetic or enum-mapping bugs that produce off-by-one values.","solutions":["Use the declared constants: TextInputLayout.BOX_BACKGROUND_NONE, BOX_BACKGROUND_FILLED, BOX_BACKGROUND_OUTLINE.","Validate/normalize any data-driven int to one of the three before calling setBoxBackgroundMode.","Check XML app:boxBackgroundMode values (none, filled, outline)."],"exampleFix":"// before\ntil.setBoxBackgroundMode(modeFromPrefs); // e.g. 5 -> throws\n\n// after\nint mode = (modeFromPrefs == BOX_BACKGROUND_FILLED || modeFromPrefs == BOX_BACKGROUND_OUTLINE)\n    ? modeFromPrefs : BOX_BACKGROUND_NONE;\ntil.setBoxBackgroundMode(mode);","handlingStrategy":"validation","validationCode":"private boolean isValidBoxBackgroundMode(int mode) {\n  return mode == TextInputLayout.BOX_BACKGROUND_NONE\n      || mode == TextInputLayout.BOX_BACKGROUND_FILLED\n      || mode == TextInputLayout.BOX_BACKGROUND_OUTLINE;\n}\n// usage: if (isValidBoxBackgroundMode(mode)) til.setBoxBackgroundMode(mode);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass BOX_BACKGROUND_* constants.","Validate persisted/imported mode ints against the constant set.","Prefer styles (FilledBox/OutlinedBox) over runtime box-mode switching."],"tags":["textinputlayout","validation","box-background-mode","android"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}