Tencent/QMUI_Android · error · IllegalArgumentException

Threshold value should be between 0 and 1.0

Error message

Threshold value should be between 0 and 1.0

What it means

SwipeBackLayout.setScrollThresHold() sets the fraction of the view's width the user must drag before the back gesture commits. Values <= 0 or >= 1.0 make the threshold meaningless (always/never trigger), so the setter validates and throws IllegalArgumentException with a clear message.

Source

Thrown at arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java:270

            return;
        }
        mListeners.clear();
        mListeners = null;
    }

    public void setOnInsetsHandler(OnInsetsHandler insetsHandler) {
        mOnInsetsHandler = insetsHandler;
    }

    /**
     * Set scroll threshold, we will close the activity, when scrollPercent over
     * this value
     *
     * @param threshold
     */
    public void setScrollThresHold(float threshold) {
        if (threshold >= 1.0f || threshold <= 0) {
            throw new IllegalArgumentException("Threshold value should be between 0 and 1.0");
        }
        mScrollThreshold = threshold;
    }

    /**
     * Set a drawable used for edge shadow.
     *
     * @param shadow   Drawable to use
     * @param edgeFlag Combination of edge flags describing the edge to set
     */
    public void setShadow(Drawable shadow, int edgeFlag) {
        if ((edgeFlag & EDGE_LEFT) != 0) {
            mShadowLeft = shadow;
        } else if ((edgeFlag & EDGE_RIGHT) != 0) {
            mShadowRight = shadow;
        } else if ((edgeFlag & EDGE_BOTTOM) != 0) {
            mShadowBottom = shadow;
        } else if ((edgeFlag & EDGE_TOP) != 0) {

View on GitHub (pinned to 026e7d4866)

Solutions

  1. Pass a strict fraction in (0, 1), e.g. setScrollThresHold(0.5f) for a 50% threshold.
  2. Convert percent input with value / 100f and clamp: Math.max(0.01f, Math.min(0.99f, v)).
  3. Guard the call site: only invoke the setter when 0 < threshold && threshold < 1.
  4. If the value comes from config/preferences, validate on read and fall back to the default 0.5f.

Example fix

// before
swipeBackLayout.setScrollThresHold(userPercent); // e.g. 50
// after
float threshold = Math.max(0.01f, Math.min(0.99f, userPercent / 100f));
swipeBackLayout.setScrollThresHold(threshold);
Defensive patterns

Strategy: validation

Validate before calling

float t = userPercent / 100f;
if (t <= 0f || t >= 1.0f) throw new IllegalArgumentException("threshold must be in (0,1): " + userPercent);
swipeBackLayout.setScrollThresHold(t);

Type guard

boolean isValidThreshold(float t) { return t > 0f && t < 1.0f; }

Try / catch

try {
    swipeBackLayout.setScrollThresHold(candidate);
} catch (IllegalArgumentException e) {
    swipeBackLayout.setScrollThresHold(0.5f); // safe default
}

Prevention

When it happens

Trigger: Calling swipeBackLayout.setScrollThresHold(x) with x <= 0f or x >= 1.0f — e.g. passing 0, 1, 1.0f, a percentage expressed as 0-100, or a computed value that drifts outside (0,1).

Common situations: Configuring swipe-back from user preferences where a 0-100 percent scale is passed unconverted, dividing/multiplying errors producing 1.0 or 0, and copy-pasted defaults like 1f.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Tencent/QMUI_Android@026e7d4866 (2026-09-06). Data as JSON: /api/errors/c00853315032b490. Report an issue: GitHub.