{"record":{"id":"9feb1578b10d8b63","repo":"TheAlgorithms/Java","slug":"maxstep-should-be-greater-than-zero","errorCode":null,"errorMessage":"maxStep should be greater than zero","messagePattern":"maxStep should be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/Mandelbrot.java","lineNumber":85,"sourceCode":"     * @param imageHeight The height of the rendered image.\n     * @param figureCenterX The x-coordinate of the center of the figure.\n     * @param figureCenterY The y-coordinate of the center of the figure.\n     * @param figureWidth The width of the figure.\n     * @param maxStep Maximum number of steps to check for divergent behavior.\n     * @param useDistanceColorCoding Render in color or black and white.\n     * @return The image of the rendered Mandelbrot set.\n     */\n    public static BufferedImage getImage(int imageWidth, int imageHeight, double figureCenterX, double figureCenterY, double figureWidth, int maxStep, boolean useDistanceColorCoding) {\n        if (imageWidth <= 0) {\n            throw new IllegalArgumentException(\"imageWidth should be greater than zero\");\n        }\n\n        if (imageHeight <= 0) {\n            throw new IllegalArgumentException(\"imageHeight should be greater than zero\");\n        }\n\n        if (maxStep <= 0) {\n            throw new IllegalArgumentException(\"maxStep should be greater than zero\");\n        }\n\n        BufferedImage image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB);\n        double figureHeight = figureWidth / imageWidth * imageHeight;\n\n        // loop through the image-coordinates\n        for (int imageX = 0; imageX < imageWidth; imageX++) {\n            for (int imageY = 0; imageY < imageHeight; imageY++) {\n                // determine the figure-coordinates based on the image-coordinates\n                double figureX = figureCenterX + ((double) imageX / imageWidth - 0.5) * figureWidth;\n                double figureY = figureCenterY + ((double) imageY / imageHeight - 0.5) * figureHeight;\n\n                double distance = getDistance(figureX, figureY, maxStep);\n\n                // color the corresponding pixel based on the selected coloring-function\n                image.setRGB(imageX, imageY, useDistanceColorCoding ? colorCodedColorMap(distance).getRGB() : blackAndWhiteColorMap(distance).getRGB());\n            }\n        }","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/Mandelbrot.java#L67-L103","documentation":"Thrown by Mandelbrot.getImage when maxStep <= 0. maxStep is the iteration cap used to decide whether a point diverges (escapes the Mandelbrot set); zero or negative steps means the escape loop never runs, so the library rejects it to avoid a meaningless all-interior render.","triggerScenarios":"Calling getImage(..., maxStep, ...) with maxStep of 0 or negative; passing a quality/precision setting that maps to 0 iterations.","commonSituations":"A 'quality' slider mapped to a count that can reach 0; CLI/default value unset resolving to 0; logic that subtracts from maxStep until it hits 0.","solutions":["Pass a positive maxStep (e.g. 256 or 1000 for finer detail).","Default maxStep to a reasonable positive value when unset.","Clamp quality-derived iteration counts to a minimum of 1.","Validate the parameter at the boundary where it is parsed."],"exampleFix":"// before\nBufferedImage img = Mandelbrot.getImage(width, height, cx, cy, fw, maxStep, color); // maxStep may be 0\n\n// after\nint steps = maxStep > 0 ? maxStep : 256;\nBufferedImage img = Mandelbrot.getImage(width, height, cx, cy, fw, steps, color);","handlingStrategy":"validation","validationCode":"if (maxStep <= 0) maxStep = 256;\nBufferedImage img = Mandelbrot.getImage(imageWidth, imageHeight, cx, cy, fw, maxStep, color);","typeGuard":"public static boolean isPositiveIterations(int steps) {\n    return steps > 0;\n}","tryCatchPattern":"try {\n    img = Mandelbrot.getImage(w, h, cx, cy, fw, maxStep, color);\n} catch (IllegalArgumentException e) {\n    img = Mandelbrot.getImage(w, h, cx, cy, fw, 256, color);\n}","preventionTips":["Clamp quality-derived iteration counts to a minimum of 1.","Default maxStep to a positive value (256-1000) when unset.","Validate iterations where the parameter is parsed."],"tags":["validation","graphics","fractal","iteration","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}