{"record":{"id":"f8fb47f7ecfd9cf0","repo":"MuntashirAkon/AppManager","slug":"offset-must-be-greater-than-or-equal-to-0","errorCode":null,"errorMessage":"offset must be greater than or equal to 0","messagePattern":"offset must be greater than or equal to 0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java","lineNumber":1076,"sourceCode":"     */\n    @FloatRange(from = 0.0f, to = 1.0f)\n    public float getHalfExpandedRatio() {\n        return halfExpandedRatio;\n    }\n\n    /**\n     * Determines the top offset of the BottomSheet in the {@link #STATE_EXPANDED} state when\n     * fitsToContent is false. The default value is 0, which results in the sheet matching the\n     * parent's top.\n     *\n     * @param offset an integer value greater than equal to 0, representing the {@link\n     *     #STATE_EXPANDED} offset. Value must not exceed the offset in the half expanded state.\n     * @attr ref\n     *     com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_expandedOffset\n     */\n    public void setExpandedOffset(int offset) {\n        if (offset < 0) {\n            throw new IllegalArgumentException(\"offset must be greater than or equal to 0\");\n        }\n        this.expandedOffset = offset;\n        updateDrawableForTargetState(state, /* animate= */ true);\n    }\n\n    /**\n     * Returns the current expanded offset. If {@code fitToContents} is true, it will automatically\n     * pick the offset depending on the height of the content.\n     *\n     * @attr ref\n     *     com.google.android.material.R.styleable#BottomSheetBehavior_Layout_behavior_expandedOffset\n     */\n    public int getExpandedOffset() {\n        return fitToContents\n                ? fitToContentsOffset\n                : Math.max(expandedOffset, paddingTopSystemWindowInsets ? 0 : insetTop);\n    }\n","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/ui/src/main/java/io/github/muntashirakon/dialog/BottomSheetBehavior.java#L1058-L1094","documentation":"setExpandedOffset() requires a non-negative pixel offset from the expanded position. Negative offsets are physically meaningless on screen, so the behavior throws IllegalArgumentException. Valid values are >= 0 and must not exceed the half-expanded offset.","triggerScenarios":"Calling setExpandedOffset(-1) or any negative int, typically from a computed dip-to-pixel conversion that produced a negative value or a sign error.","commonSituations":"Passing a negative margin/offset constant; computing offset from resources that resolve to negative values on some configurations.","solutions":["Pass a non-negative offset (clamp with Math.max(0, offset))","Fix the computation/source that yields the negative value","Also ensure the offset does not exceed the half-expanded offset"],"exampleFix":"// before\nbehavior.setExpandedOffset(offsetPx);\n// after\nbehavior.setExpandedOffset(Math.max(0, offsetPx));","handlingStrategy":"validation","validationCode":"if (offset >= 0) behavior.setExpandedOffset(offset);","typeGuard":null,"tryCatchPattern":"try {\n    behavior.setExpandedOffset(offset);\n} catch (IllegalArgumentException e) {\n    behavior.setExpandedOffset(0);\n}","preventionTips":["Clamp offsets with Math.max(0, offset)","Verify dip-to-pixel conversions can't go negative","Keep expandedOffset <= halfExpandedOffset"],"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"}