{"record":{"id":"53746e15635438ee","repo":"material-components/material-components-android","slug":"transient-bottom-bar-must-have-non-null-callback","errorCode":null,"errorMessage":"Transient bottom bar must have non-null callback","messagePattern":"Transient bottom bar must have non-null callback","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java","lineNumber":361,"sourceCode":"      @NonNull ViewGroup parent,\n      @NonNull View content,\n      @NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {\n    this(parent.getContext(), parent, content, contentViewCallback);\n  }\n\n  protected BaseTransientBottomBar(\n      @NonNull Context context,\n      @NonNull ViewGroup parent,\n      @NonNull View content,\n      @NonNull com.google.android.material.snackbar.ContentViewCallback contentViewCallback) {\n    if (parent == null) {\n      throw new IllegalArgumentException(\"Transient bottom bar must have non-null parent\");\n    }\n    if (content == null) {\n      throw new IllegalArgumentException(\"Transient bottom bar must have non-null content\");\n    }\n    if (contentViewCallback == null) {\n      throw new IllegalArgumentException(\"Transient bottom bar must have non-null callback\");\n    }\n\n    targetParent = parent;\n    this.contentViewCallback = contentViewCallback;\n    this.context = context;\n\n    ThemeEnforcement.checkAppCompatTheme(context);\n\n    LayoutInflater inflater = LayoutInflater.from(context);\n    // Note that for backwards compatibility reasons we inflate a layout that is defined\n    // in the extending Snackbar class. This is to prevent breakage of apps that have custom\n    // coordinator layout behaviors that depend on that layout.\n    view = (SnackbarBaseLayout) inflater.inflate(getSnackbarBaseLayoutResId(), targetParent, false);\n    view.setBaseTransientBottomBar(this);\n    if (content instanceof SnackbarContentLayout) {\n      ((SnackbarContentLayout) content)\n          .updateActionTextColorAlphaIfNeeded(view.getActionTextColorAlpha());\n      ((SnackbarContentLayout) content).setMaxInlineActionWidth(view.getMaxInlineActionWidth());","sourceCodeStart":343,"sourceCodeEnd":379,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/snackbar/BaseTransientBottomBar.java#L343-L379","documentation":"IllegalArgumentException from the BaseTransientBottomBar constructor when the ContentViewCallback is null. The callback drives the show/hide animations of the content; subclasses like Snackbar supply it automatically, so this throw mainly affects code constructing BaseTransientBottomBar subclasses directly with a null callback.","triggerScenarios":"Building a custom transient bottom bar and passing null for the ContentViewCallback (e.g. animations deemed unnecessary); DI or reflection paths where the callback parameter was omitted.","commonSituations":"First-time implementations of custom transients that underestimate the callback's role; refactorings that dropped the callback argument.","solutions":["Provide a real ContentViewCallback; if no animation is wanted, implement a no-op callback rather than null.","Reuse Snackbar's BaseCallback-style patterns or copy a minimal no-op implementation.","Null-check constructor arguments in the subclass before delegating to super."],"exampleFix":"// before\nnew MyTransientBar(parent, content, null); // throws\n\n// after\nnew MyTransientBar(parent, content, new ContentViewCallback() {\n  @Override public void animateContentIn(int delay, int duration) {}\n  @Override public void animateContentOut(int delay, int duration) {}\n});","handlingStrategy":"fallback","validationCode":"ContentViewCallback cb = (callback != null) ? callback : new ContentViewCallback() {\n  @Override public void animateContentIn(int delay, int duration) {}\n  @Override public void animateContentOut(int delay, int duration) {}\n};\nnew MyTransientBar(parent, content, cb);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provide a no-op ContentViewCallback instead of null when animations are unwanted.","Null-check subclass constructor args before delegating to super."],"tags":["android","snackbar","material-components","null-safety","immediate","custom-subclass"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}