{"record":{"id":"3b4c619b168de47a","repo":"TheAlgorithms/Java","slug":"octavecount-must-be-1","errorCode":null,"errorMessage":"octaveCount must be >= 1","messagePattern":"octaveCount must be >= 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/PerlinNoise.java","lineNumber":59,"sourceCode":"\n    /**\n     * Generate a 2D array of blended noise values normalized to [0, 1].\n     *\n     * @param width       width of the noise array (columns)\n     * @param height      height of the noise array (rows)\n     * @param octaveCount number of octaves (layers) to blend; must be >= 1\n     * @param persistence per-octave amplitude multiplier in (0, 1]\n     * @param seed        seed for the random base grid\n     * @return a {@code width x height} array containing blended noise values in [0,\n     *         1]\n     */\n    static float[][] generatePerlinNoise(int width, int height, int octaveCount, float persistence, long seed) {\n        if (width <= 0 || height <= 0) {\n            throw new IllegalArgumentException(\"width and height must be > 0\");\n        }\n\n        if (octaveCount < 1) {\n            throw new IllegalArgumentException(\"octaveCount must be >= 1\");\n        }\n        if (!(persistence > 0f && persistence <= 1f)) { // using > to exclude 0 and NaN\n            throw new IllegalArgumentException(\"persistence must be in (0, 1]\");\n        }\n        final float[][] base = createBaseGrid(width, height, seed);\n        final float[][][] layers = createLayers(base, width, height, octaveCount);\n        return blendAndNormalize(layers, width, height, persistence);\n    }\n\n    /** Create the base random lattice values in [0,1). */\n    static float[][] createBaseGrid(int width, int height, long seed) {\n        final float[][] base = new float[width][height];\n        Random random = new Random(seed);\n        for (int x = 0; x < width; x++) {\n            for (int y = 0; y < height; y++) {\n                base[x][y] = random.nextFloat();\n            }\n        }","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/PerlinNoise.java#L41-L77","documentation":"Thrown by PerlinNoise.generatePerlinNoise when octaveCount < 1. Octaves are the blended noise layers; at least one layer is required to produce any output. Zero or negative octaves would leave the layer array empty and produce no noise, so the method rejects it.","triggerScenarios":"Calling generatePerlinNoise(..., octaveCount, ...) with octaveCount of 0 or negative; a 'detail level' setting mapped to 0.","commonSituations":"A detail/quality slider that can reach 0; default value unset resolving to 0; logic that subtracts from octaveCount until it hits 0.","solutions":["Pass octaveCount >= 1 (4-8 is typical for natural-looking noise).","Default octaveCount to a positive value when unset.","Clamp detail-derived octave counts to a minimum of 1.","Validate the parameter at the boundary where it is parsed."],"exampleFix":"// before\nfloat[][] noise = PerlinNoise.generatePerlinNoise(w, h, octaves, persistence, seed); // octaves may be 0\n\n// after\nint oct = Math.max(1, octaves);\nfloat[][] noise = PerlinNoise.generatePerlinNoise(w, h, oct, persistence, seed);","handlingStrategy":"validation","validationCode":"int octaves = Math.max(1, octaveCount);\nfloat[][] noise = PerlinNoise.generatePerlinNoise(width, height, octaves, persistence, seed);","typeGuard":"public static boolean isPositiveOctaves(int octaves) {\n    return octaves >= 1;\n}","tryCatchPattern":"try {\n    noise = PerlinNoise.generatePerlinNoise(w, h, oct, p, seed);\n} catch (IllegalArgumentException e) {\n    noise = PerlinNoise.generatePerlinNoise(w, h, 1, p, seed);\n}","preventionTips":["Always pass octaveCount >= 1; 4-8 is typical.","Clamp detail-level sliders to a minimum of 1.","Default octaves to a positive value when unset."],"tags":["validation","perlin-noise","procedural-generation","input-validation","iteration"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}