{"record":{"id":"80d3d6c2712346e9","repo":"MuntashirAkon/AppManager","slug":"ratio-must-be-a-float-value-between-0-and-1","errorCode":null,"errorMessage":"ratio must be a float value between 0 and 1","messagePattern":"ratio must be a float value between 0 and 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java","lineNumber":1043,"sourceCode":"    public int getPeekHeight() {\n        return peekHeightAuto ? PEEK_HEIGHT_AUTO : peekHeight;\n    }\n\n    /**\n     * Determines the height of the BottomSheet in the {@link #STATE_HALF_EXPANDED} state. The\n     * material guidelines recommended a value of 0.5, which results in the sheet filling half of the\n     * parent. The height of the BottomSheet will be smaller as this ratio is decreased and taller as\n     * it is increased. The default value is 0.5.\n     *\n     * @param ratio a float between 0 and 1, representing the {@link #STATE_HALF_EXPANDED} ratio.\n     * @attr ref\n     *     com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_halfExpandedRatio\n     */\n    public void setHalfExpandedRatio(\n            @FloatRange(from = 0.0f, to = 1.0f, fromInclusive = false, toInclusive = false) float ratio) {\n\n        if ((ratio <= 0) || (ratio >= 1)) {\n            throw new IllegalArgumentException(\"ratio must be a float value between 0 and 1\");\n        }\n        this.halfExpandedRatio = ratio;\n        // If sheet is already laid out, recalculate the half expanded offset based on new setting.\n        // Otherwise, let onLayoutChild handle this later.\n        if (viewRef != null) {\n            calculateHalfExpandedOffset();\n        }\n    }\n\n    /**\n     * Gets the ratio for the height of the BottomSheet in the {@link #STATE_HALF_EXPANDED} state.\n     *\n     * @attr ref\n     *     com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_halfExpandedRatio\n     */\n    @FloatRange(from = 0.0f, to = 1.0f)\n    public float getHalfExpandedRatio() {\n        return halfExpandedRatio;","sourceCodeStart":1025,"sourceCodeEnd":1061,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java#L1025-L1061","documentation":"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.","triggerScenarios":"Calling behavior.setHalfExpandedRatio(0f), setHalfExpandedRatio(1f), or any value outside (0,1), including values computed from layout math that collapse to 0 or 1.","commonSituations":"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.","solutions":["Pass a float strictly between 0 and 1 (e.g. 0.5f)","Clamp the computed value into the open interval before calling","Remove or fix the invalid XML attribute behavior_halfExpandedRatio if set from styles"],"exampleFix":"// before\nbehavior.setHalfExpandedRatio(50);\n// after\nfloat ratio = Math.min(0.99f, Math.max(0.01f, desired));\nbehavior.setHalfExpandedRatio(ratio);","handlingStrategy":"validation","validationCode":"if (ratio <= 0f || ratio >= 1f) throw new IllegalArgumentException(\"ratio must be in (0,1)\");\nbehavior.setHalfExpandedRatio(ratio);","typeGuard":null,"tryCatchPattern":"try {\n    behavior.setHalfExpandedRatio(ratio);\n} catch (IllegalArgumentException e) {\n    behavior.setHalfExpandedRatio(0.5f);\n}","preventionTips":["Clamp ratios into the open interval (0,1) before setting","Remember the attr is a fraction, not a percentage","Guard computed values against divide-by-zero producing 0 or 1"],"tags":["android","bottomsheet","argument-range"],"backgroundTag":"value-out-of-range","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}