MuntashirAkon/AppManager · error · IllegalArgumentException

ratio must be a float value between 0 and 1

Error message

ratio must be a float value between 0 and 1

What it means

setHalfExpandedRatio() validates that the half-expanded anchor ratio lies strictly between 0 and 1 (exclusive). A ratio of 0 or less or 1 or more makes the half-expanded offset meaningless, so BottomSheetBehavior throws IllegalArgumentException. This is a fork of Material Components' BottomSheetBehavior with the same validation.

Solutions

  1. Pass a float strictly between 0 and 1 (e.g. 0.5f)
  2. Clamp the computed value into the open interval before calling
  3. Remove or fix the invalid XML attribute behavior_halfExpandedRatio if set from styles

Example fix

// before
behavior.setHalfExpandedRatio(50);
// after
float ratio = Math.min(0.99f, Math.max(0.01f, desired));
behavior.setHalfExpandedRatio(ratio);
Defensive patterns

Strategy: validation

Validate before calling

if (ratio <= 0f || ratio >= 1f) throw new IllegalArgumentException("ratio must be in (0,1)");
behavior.setHalfExpandedRatio(ratio);

Try / catch

try {
    behavior.setHalfExpandedRatio(ratio);
} catch (IllegalArgumentException e) {
    behavior.setHalfExpandedRatio(0.5f);
}

Prevention

When it happens

Trigger: Calling behavior.setHalfExpandedRatio(0f), setHalfExpandedRatio(1f), or any value outside (0,1), including values computed from layout math that collapse to 0 or 1.

Common situations: Misreading the attr as a percentage (e.g. passing 50 instead of 0.5), or computing ratio = offset/height where height is 0 or offset equals height.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/80d3d6c2712346e9. Report an issue: GitHub.

Appendix: source

Thrown at libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java:1043

    public int getPeekHeight() {
        return peekHeightAuto ? PEEK_HEIGHT_AUTO : peekHeight;
    }

    /**
     * Determines the height of the BottomSheet in the {@link #STATE_HALF_EXPANDED} state. The
     * material guidelines recommended a value of 0.5, which results in the sheet filling half of the
     * parent. The height of the BottomSheet will be smaller as this ratio is decreased and taller as
     * it is increased. The default value is 0.5.
     *
     * @param ratio a float between 0 and 1, representing the {@link #STATE_HALF_EXPANDED} ratio.
     * @attr ref
     *     com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_halfExpandedRatio
     */
    public void setHalfExpandedRatio(
            @FloatRange(from = 0.0f, to = 1.0f, fromInclusive = false, toInclusive = false) float ratio) {

        if ((ratio <= 0) || (ratio >= 1)) {
            throw new IllegalArgumentException("ratio must be a float value between 0 and 1");
        }
        this.halfExpandedRatio = ratio;
        // If sheet is already laid out, recalculate the half expanded offset based on new setting.
        // Otherwise, let onLayoutChild handle this later.
        if (viewRef != null) {
            calculateHalfExpandedOffset();
        }
    }

    /**
     * Gets the ratio for the height of the BottomSheet in the {@link #STATE_HALF_EXPANDED} state.
     *
     * @attr ref
     *     com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_halfExpandedRatio
     */
    @FloatRange(from = 0.0f, to = 1.0f)
    public float getHalfExpandedRatio() {
        return halfExpandedRatio;

View on GitHub (pinned to 0152f468fc)