{"record":{"id":"c00853315032b490","repo":"Tencent/QMUI_Android","slug":"threshold-value-should-be-between-0-and-1-0","errorCode":null,"errorMessage":"Threshold value should be between 0 and 1.0","messagePattern":"Threshold value should be between 0 and 1\\.0","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java","lineNumber":270,"sourceCode":"            return;\n        }\n        mListeners.clear();\n        mListeners = null;\n    }\n\n    public void setOnInsetsHandler(OnInsetsHandler insetsHandler) {\n        mOnInsetsHandler = insetsHandler;\n    }\n\n    /**\n     * Set scroll threshold, we will close the activity, when scrollPercent over\n     * this value\n     *\n     * @param threshold\n     */\n    public void setScrollThresHold(float threshold) {\n        if (threshold >= 1.0f || threshold <= 0) {\n            throw new IllegalArgumentException(\"Threshold value should be between 0 and 1.0\");\n        }\n        mScrollThreshold = threshold;\n    }\n\n    /**\n     * Set a drawable used for edge shadow.\n     *\n     * @param shadow   Drawable to use\n     * @param edgeFlag Combination of edge flags describing the edge to set\n     */\n    public void setShadow(Drawable shadow, int edgeFlag) {\n        if ((edgeFlag & EDGE_LEFT) != 0) {\n            mShadowLeft = shadow;\n        } else if ((edgeFlag & EDGE_RIGHT) != 0) {\n            mShadowRight = shadow;\n        } else if ((edgeFlag & EDGE_BOTTOM) != 0) {\n            mShadowBottom = shadow;\n        } else if ((edgeFlag & EDGE_TOP) != 0) {","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/arch/src/main/java/com/qmuiteam/qmui/arch/SwipeBackLayout.java#L252-L288","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Pass a strict fraction in (0, 1), e.g. setScrollThresHold(0.5f) for a 50% threshold.","Convert percent input with value / 100f and clamp: Math.max(0.01f, Math.min(0.99f, v)).","Guard the call site: only invoke the setter when 0 < threshold && threshold < 1.","If the value comes from config/preferences, validate on read and fall back to the default 0.5f."],"exampleFix":"// before\nswipeBackLayout.setScrollThresHold(userPercent); // e.g. 50\n// after\nfloat threshold = Math.max(0.01f, Math.min(0.99f, userPercent / 100f));\nswipeBackLayout.setScrollThresHold(threshold);","handlingStrategy":"validation","validationCode":"float t = userPercent / 100f;\nif (t <= 0f || t >= 1.0f) throw new IllegalArgumentException(\"threshold must be in (0,1): \" + userPercent);\nswipeBackLayout.setScrollThresHold(t);","typeGuard":"boolean isValidThreshold(float t) { return t > 0f && t < 1.0f; }","tryCatchPattern":"try {\n    swipeBackLayout.setScrollThresHold(candidate);\n} catch (IllegalArgumentException e) {\n    swipeBackLayout.setScrollThresHold(0.5f); // safe default\n}","preventionTips":["Clamp user/config-derived values into (0,1) before calling","Convert percentages (0-100) to fractions","Write a unit test boundary-checking the setter"],"tags":["android","swipe-back","validation","ui"],"backgroundTag":"invalid-argument-value","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}