{"record":{"id":"be7dbb6b00a8a56f","repo":"apache/flink","slug":"the-cpu-cores-should-be-positive","errorCode":null,"errorMessage":"The cpu cores should be positive.","messagePattern":"The cpu cores should be positive\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java","lineNumber":155,"sourceCode":"\n    /** Builder for {@link SlotSharingGroup}. */\n    @Experimental\n    public static class Builder {\n        private final String name;\n        private Double cpuCores;\n        private MemorySize taskHeapMemory;\n        private MemorySize taskOffHeapMemory;\n        private MemorySize managedMemory;\n        private final Map<String, Double> externalResources = new HashMap<>();\n\n        private Builder(String name) {\n            this.name = name;\n        }\n\n        /** Set the CPU cores for this SlotSharingGroup. */\n        public Builder setCpuCores(double cpuCores) {\n            if (cpuCores <= 0) {\n                throw new IllegalArgumentException(\"The cpu cores should be positive.\");\n            }\n            this.cpuCores = cpuCores;\n            return this;\n        }\n\n        /** Set the task heap memory for this SlotSharingGroup. */\n        public Builder setTaskHeapMemory(MemorySize taskHeapMemory) {\n            if (taskHeapMemory.compareTo(MemorySize.ZERO) <= 0) {\n                throw new IllegalArgumentException(\"The task heap memory should be positive.\");\n            }\n            this.taskHeapMemory = taskHeapMemory;\n            return this;\n        }\n\n        /** Set the task heap memory for this SlotSharingGroup in MB. */\n        public Builder setTaskHeapMemoryMB(int taskHeapMemoryMB) {\n            if (taskHeapMemoryMB <= 0) {\n                throw new IllegalArgumentException(\"The task heap memory should be positive.\");","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java#L137-L173","documentation":"SlotSharingGroup.Builder.setPassword-style validation: setCpuCores(double) rejects values <= 0 with this IllegalArgumentException, because a slot sharing group's resource spec must declare a strictly positive CPU share. Zero or negative cores would make the group unschedulable, so the builder fails fast.","triggerScenarios":"Calling SlotSharingGroup.newBuilder(name).setCpuCores(0), setCpuCores(-1), or passing a computed value (e.g. totalCores - reserved) that evaluates to 0 or negative.","commonSituations":"Deriving cpuCores from environment variables or fractions of TaskManager slots that round to zero; configuration templates defaulting to 0 meaning 'unset'; arithmetic that subtracts too much.","solutions":["Set a positive value, e.g. setCpuCores(1.0) or a fraction like 0.5.","Validate derived values before building: if the computed cores are <= 0, fall back to a documented default.","Check the option's docs for minimum supported values."],"exampleFix":"// before\n.newBuilder(\"group\").setCpuCores(totalCores - reservedCores) // 0.0 when fully reserved\n\n// after\n.newBuilder(\"group\").setCpuCores(Math.max(totalCores - reservedCores, 0.1))","handlingStrategy":"validation","validationCode":"if (!(cpuCores > 0)) throw new IllegalArgumentException(\"cpuCores must be > 0, got \" + cpuCores);\nSlotSharingGroup.newBuilder(name).setCpuCores(cpuCores);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default cpuCores to a positive value (e.g. 1.0) in config plumbing.","Clamp computed cores with Math.max(value, minimum).","Validate resource values at the config boundary, not inside builders."],"tags":["configuration","resource-spec","validation","builder"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}