{"record":{"id":"bf822ad146718243","repo":"apache/flink","slug":"divisor-must-be-0","errorCode":null,"errorMessage":"divisor must be != 0","messagePattern":"divisor must be != 0","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java","lineNumber":222,"sourceCode":"        return new MemorySize(Math.subtractExact(this.bytes, that.bytes));\n    }\n\n    public MemorySize multiply(double multiplier) {\n        if (multiplier < 0) {\n            throw new IllegalArgumentException(\"multiplier must be >= 0\");\n        }\n\n        BigDecimal product =\n                BigDecimal.valueOf(this.bytes).multiply(BigDecimal.valueOf(multiplier));\n        if (product.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0) {\n            throw new ArithmeticException(\"long overflow\");\n        }\n        return new MemorySize(product.longValue());\n    }\n\n    public MemorySize divide(long by) {\n        if (by < 0) {\n            throw new IllegalArgumentException(\"divisor must be != 0\");\n        }\n        return new MemorySize(bytes / by);\n    }\n\n    // ------------------------------------------------------------------------\n    //  Parsing\n    // ------------------------------------------------------------------------\n\n    /**\n     * Parses the given string as as MemorySize.\n     *\n     * @param text The string to parse\n     * @return The parsed MemorySize\n     * @throws IllegalArgumentException Thrown, if the expression cannot be parsed.\n     */\n    public static MemorySize parse(String text) throws IllegalArgumentException {\n        return new MemorySize(parseBytes(text));\n    }","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core-api/src/main/java/org/apache/flink/configuration/MemorySize.java#L204-L240","documentation":"MemorySize.divide(long by) throws IllegalArgumentException(\"divisor must be != 0\") when the divisor is negative (the message text is imprecise — the guard actually tests by < 0, so only negative divisors reach it). A zero divisor bypasses this guard and instead throws the JVM's native ArithmeticException(\"/ by zero\").","triggerScenarios":"size.divide(-4); splitting a memory budget by a slot count or parallelism that is configured negative; sign errors in derived divisor values.","commonSituations":"Dividing a total memory size by task slots, parallelism, or worker count where that value is read from config and can be negative or zero on misconfiguration.","solutions":["Validate the divisor is a positive number before dividing","Fix the upstream config so slot/parallelism counts are >= 1","Note the message says '!= 0' but only negative values hit it; zero gives a separate '/ by zero' ArithmeticException — guard both"],"exampleFix":"// before\nMemorySize perSlot = total.divide(slots); // slots from config, may be <= 0\n\n// after\nif (slots <= 0) {\n    throw new IllegalArgumentException(\"slots must be positive, got \" + slots);\n}\nMemorySize perSlot = total.divide(slots);","handlingStrategy":"validation","validationCode":"if (by <= 0) {\n    throw new IllegalArgumentException(\"divisor must be positive, got \" + by);\n}\nMemorySize share = total.divide(by);","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException | ArithmeticException e) { /* covers negative divisor and '/ by zero'; rethrow with the config key it came from */ }","preventionTips":["Guard both negative AND zero — zero gives a separate JVM '/ by zero' error","Validate slot/parallelism counts from config are >= 1 before dividing budgets"],"tags":["memory","validation","arithmetic","flink-core-api"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}