{"record":{"id":"52022dc04939ac7c","repo":"apache/flink","slug":"the-task-heap-memory-should-be-positive","errorCode":null,"errorMessage":"The task heap memory should be positive.","messagePattern":"The task heap memory 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":164,"sourceCode":"        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.\");\n            }\n            this.taskHeapMemory = MemorySize.ofMebiBytes(taskHeapMemoryMB);\n            return this;\n        }\n\n        /** Set the task off-heap memory for this SlotSharingGroup. */\n        public Builder setTaskOffHeapMemory(MemorySize taskOffHeapMemory) {\n            this.taskOffHeapMemory = taskOffHeapMemory;\n            return this;","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java#L146-L182","documentation":"SlotSharingGroup.Builder.setTaskHeapMemory(MemorySize) requires the task heap to be strictly greater than MemorySize.ZERO. Memory of zero or negative bytes is rejected because a group declaring resources must declare a usable heap, matching the requirement that cpu cores and task heap are the two mandatory resources.","triggerScenarios":"Calling setTaskHeapMemory(MemorySize.ZERO), a negative MemorySize (MEMORY_SIZE parses negative byte counts like \"-1m\"), or a computed size that evaluates to 0 bytes.","commonSituations":"Parsing memory strings with a sign error (\"-256m\"), subtracting managed/off-heap from a total and hitting zero, defaulting to MemorySize.ZERO as 'unset' in config plumbing.","solutions":["Provide a positive heap size: setTaskHeapMemory(MemorySize.ofMebiBytes(256)).","Fix sign errors in memory strings and ensure subtraction-based sizing keeps a positive remainder.","Use a non-zero sentinel or Optional<MemorySize> for 'unset' instead of MemorySize.ZERO."],"exampleFix":"# before\ntask.heap.size=-256m\n\n# after\ntask.heap.size=256m","handlingStrategy":"validation","validationCode":"if (heap == null || heap.compareTo(MemorySize.ZERO) <= 0) throw new IllegalArgumentException(\"task heap must be positive\");\nbuilder.setTaskHeapMemory(heap);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never use MemorySize.ZERO as 'unset'; use null or Optional.","Reject negative memory strings (\"-256m\") at parse time.","Ensure subtraction-based sizing leaves a positive remainder."],"tags":["configuration","memory","resource-spec","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}