{"record":{"id":"de1deb3ff6926293","repo":"TheAlgorithms/Java","slug":"classification-ratio-must-be-between-0-and-1-excl","errorCode":null,"errorMessage":"Classification ratio must be between 0 and 1 (exclusive).","messagePattern":"Classification ratio must be between 0 and 1 \\(exclusive\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/sorts/FlashSort.java","lineNumber":32,"sourceCode":" * <ol>\n *     <li>Finds the minimum and maximum values in the array.</li>\n *     <li>Initializes a classification array `L` to keep track of the number of elements in each class.</li>\n *     <li>Computes a normalization constant `c1` to map elements into classes.</li>\n *     <li>Classifies each element of the array into the corresponding bucket in the classification array.</li>\n *     <li>Transforms the classification array to compute the starting indices of each bucket.</li>\n *     <li>Permutes the elements of the array into sorted order based on the classification.</li>\n *     <li>Uses insertion sort for the final arrangement to ensure complete sorting.</li>\n * </ol>\n */\npublic class FlashSort implements SortAlgorithm {\n    private double classificationRatio = 0.45;\n\n    public FlashSort() {\n    }\n\n    public FlashSort(double classificationRatio) {\n        if (classificationRatio <= 0 || classificationRatio >= 1) {\n            throw new IllegalArgumentException(\"Classification ratio must be between 0 and 1 (exclusive).\");\n        }\n        this.classificationRatio = classificationRatio;\n    }\n\n    public double getClassificationRatio() {\n        return classificationRatio;\n    }\n\n    public void setClassificationRatio(double classificationRatio) {\n        if (classificationRatio <= 0 || classificationRatio >= 1) {\n            throw new IllegalArgumentException(\"Classification ratio must be between 0 and 1 (exclusive).\");\n        }\n        this.classificationRatio = classificationRatio;\n    }\n\n    /**\n     * Sorts an array using the Flash Sort algorithm.\n     *","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/sorts/FlashSort.java#L14-L50","documentation":"Thrown by the FlashSort(double) constructor when classificationRatio <= 0 or >= 1. The classification ratio positions each element into a bucket based on its value relative to the min/max range; values of 0 or 1 collapse the classification into a single bucket and break the algorithm. Both the constructor and setter enforce the same (0,1) open interval.","triggerScenarios":"new FlashSort(0.0); new FlashSort(1.0); new FlashSort(1.5); new FlashSort(-0.2); calling setClassificationRatio with the same out-of-range values.","commonSituations":"Loading the ratio from config with a typo or missing value defaulting to 0; computing the ratio from a formula that can equal 0 or 1 at boundary inputs; exposing it as a user-tunable knob without validation.","solutions":["Validate 0 < ratio < 1 before constructing or calling the setter.","Clamp config-derived ratios to a safe default (e.g. 0.45) when out of range.","Document the open interval (0,1) in your config schema and validate at parse time."],"exampleFix":"// before\nFlashSort s = new FlashSort(ratio);\n\n// after\ndouble r = (ratio <= 0 || ratio >= 1) ? 0.45 : ratio;\nFlashSort s = new FlashSort(r);","handlingStrategy":"validation","validationCode":"if (classificationRatio <= 0 || classificationRatio >= 1) throw new IllegalArgumentException(\"ratio must be in (0,1)\");","typeGuard":"public static boolean isValidRatio(double r) { return r > 0 && r < 1; }","tryCatchPattern":null,"preventionTips":["Validate config-derived ratios at parse time against the open interval (0,1).","Clamp to a safe default (0.45) when out of range.","Constrain UI sliders to the open interval and disallow exact 0/1."],"tags":["sorting","config","range-validation","constructor"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}