{"record":{"id":"88c8eaf3dba18550","repo":"TheAlgorithms/Java","slug":"imageheight-should-be-greater-than-zero","errorCode":null,"errorMessage":"imageHeight should be greater than zero","messagePattern":"imageHeight should be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/Mandelbrot.java","lineNumber":81,"sourceCode":"     * area of the Mandelbrot set is roughly between \"-1.5 < x < 0.5\" and \"-1 <\n     * y < 1\" in the figure-coordinates.\n     *\n     * @param imageWidth The width of the rendered image.\n     * @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","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/Mandelbrot.java#L63-L99","documentation":"Thrown by Mandelbrot.getImage when imageHeight <= 0. The method allocates a BufferedImage of imageWidth x imageHeight and uses imageHeight in the figureHeight computation, so a non-positive height produces a degenerate image and is rejected before allocation.","triggerScenarios":"Calling getImage(..., imageHeight, ...) with imageHeight of 0 or negative; height read from a config/CLI argument that defaults to 0 when unset.","commonSituations":"Unset height parameter defaulting to 0; CLI parsing returning 0; portrait/landscape auto-calc producing 0 before a layout pass; negative height from subtraction.","solutions":["Provide a positive imageHeight (e.g. 600) when calling getImage.","Default height to a positive value when the source is missing or zero.","Validate both dimensions at the input boundary before invoking.","Make sure aspect-ratio computations cannot yield 0."],"exampleFix":"// before\nBufferedImage img = Mandelbrot.getImage(width, height, cx, cy, fw, maxStep, color); // height may be 0\n\n// after\nint h = height > 0 ? height : 600;\nBufferedImage img = Mandelbrot.getImage(width, h, cx, cy, fw, maxStep, color);","handlingStrategy":"validation","validationCode":"if (imageHeight <= 0) imageHeight = 600;\nBufferedImage img = Mandelbrot.getImage(imageWidth, imageHeight, cx, cy, fw, maxStep, color);","typeGuard":"public static boolean isPositiveDimension(int dim) {\n    return dim > 0;\n}","tryCatchPattern":"try {\n    img = Mandelbrot.getImage(w, h, cx, cy, fw, maxStep, color);\n} catch (IllegalArgumentException e) {\n    img = Mandelbrot.getImage(w, 600, cx, cy, fw, maxStep, color);\n}","preventionTips":["Default height to a positive value at config load.","Ensure aspect-ratio calculations never produce 0.","Validate both dimensions at the input boundary."],"tags":["validation","graphics","image","fractal","input-validation"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}