gyf-dev/ImmersionBar · error · IllegalArgumentException

tag不能为空

Error message

tag不能为空

What it means

addTag stores a snapshot of current BarParams under a String tag for later restoration. Because the tag is the lookup key in mTagMap, an empty/null tag is rejected with IllegalArgumentException("tag不能为空") ("tag cannot be empty").

Solutions

  1. Pass a non-empty literal or constant tag
  2. Validate the tag source (extra/config value) before calling addTag
  3. Use a guaranteed default like "default" when the dynamic value is missing

Example fix

// before
bar.addTag(getIntent().getStringExtra("theme")); // may be null
// after
String theme = getIntent().getStringExtra("theme");
if (theme != null && !theme.trim().isEmpty()) {
    bar.addTag(theme);
}
Defensive patterns

Strategy: validation

Validate before calling

if (tag != null && !tag.trim().isEmpty()) { bar.addTag(tag); }

Type guard

boolean validTag(String t) { return t != null && !t.trim().isEmpty(); }

Try / catch

try { bar.addTag(tag); } catch (IllegalArgumentException e) { Log.e(TAG, "empty tag", e); }

Prevention

When it happens

Trigger: Calling bar.addTag(null) or bar.addTag("") or a whitespace-only string (isEmpty check).

Common situations: Tag sourced from an unconfigured constant/BuildConfig field; tag read from a resource or intent extra that is missing; string interpolation producing an empty value.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of gyf-dev/ImmersionBar@8cac10cd83 (2026-09-08). Data as JSON: /api/errors/f6812148f3230008. Report an issue: GitHub.

Appendix: source

Thrown at immersionbar/src/main/java/com/gyf/immersionbar/ImmersionBar.java:4402

     *
     * @return the immersion bar
     */
    public ImmersionBar reset() {
        mBarParams = createDefaultBarParams();
        mFitsStatusBarType = FLAG_FITS_DEFAULT;
        return this;
    }

    /**
     * 给某个页面设置tag来标识这页bar的属性.
     * Add tag bar tag.
     *
     * @param tag the tag
     * @return the bar tag
     */
    public ImmersionBar addTag(String tag) {
        if (isEmpty(tag)) {
            throw new IllegalArgumentException("tag不能为空");
        }
        BarParams barParams = mBarParams.clone();
        mTagMap.put(tag, barParams);
        return this;
    }

    /**
     * 根据tag恢复到某次调用时的参数
     * Recover immersion bar.
     *
     * @param tag the tag
     * @return the immersion bar
     */
    public ImmersionBar getTag(String tag) {
        if (isEmpty(tag)) {
            throw new IllegalArgumentException("tag不能为空");
        }
        BarParams barParams = mTagMap.get(tag);

View on GitHub (pinned to 8cac10cd83)