{"record":{"id":"6c5d74d42bf9d767","repo":"apache/flink","slug":"the-cpu-cores-and-task-heap-memory-are-required-wh-6c5d74","errorCode":null,"errorMessage":"The cpu cores and task heap memory are required when specifying the resource of a slot sharing group. You need to explicitly configure them with positive value.","messagePattern":"The cpu cores and task heap memory are required when specifying the resource of a slot sharing group\\. You need to explicitly configure them with positive value\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java","lineNumber":229,"sourceCode":"\n        /** Build the SlotSharingGroup. */\n        public SlotSharingGroup build() {\n            if (cpuCores != null && taskHeapMemory != null) {\n                taskOffHeapMemory = Optional.ofNullable(taskOffHeapMemory).orElse(MemorySize.ZERO);\n                managedMemory = Optional.ofNullable(managedMemory).orElse(MemorySize.ZERO);\n                return new SlotSharingGroup(\n                        name,\n                        cpuCores,\n                        taskHeapMemory,\n                        taskOffHeapMemory,\n                        managedMemory,\n                        externalResources);\n            } else if (cpuCores != null\n                    || taskHeapMemory != null\n                    || taskOffHeapMemory != null\n                    || managedMemory != null\n                    || !externalResources.isEmpty()) {\n                throw new IllegalArgumentException(\n                        \"The cpu cores and task heap memory are required when specifying the resource of a slot sharing group. \"\n                                + \"You need to explicitly configure them with positive value.\");\n            } else {\n                return new SlotSharingGroup(name);\n            }\n        }\n    }\n}\n","sourceCodeStart":211,"sourceCodeEnd":238,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java#L211-L238","documentation":"SlotSharingGroup.Builder.build() enforces an all-or-nothing rule: either all required resource fields are set (cpuCores AND taskHeapMemory are mandatory; others optional) producing a resource-annotated group, or none are set producing a name-only group. Setting any resource field while cpuCores or taskHeapMemory is null throws this IllegalArgumentException.","triggerScenarios":"Calling build() after setting e.g. setManagedMemory(...) or setTaskOffHeapMemory(...) but omitting setCpuCores or setTaskHeapMemory; or setting only setCpuCores without heap memory.","commonSituations":"Incrementally migrating config to fine-grained resource management and setting only managed/off-heap memory; templated builders where some setters are conditional and the mandatory pair is skipped.","solutions":["Add the missing mandatory values: always pair setCpuCores(...) with setTaskHeapMemory(...) (or the MB overload).","If you do not want resource annotations, remove ALL resource setters and build a name-only group.","Centralize group construction in one factory that either sets the full mandatory pair plus optionals, or none."],"exampleFix":"// before\nSlotSharingGroup.newBuilder(\"g\")\n    .setTaskOffHeapMemory(MemorySize.ofMebiBytes(64))\n    .build(); // throws: cpuCores/taskHeapMemory missing\n\n// after\nSlotSharingGroup.newBuilder(\"g\")\n    .setCpuCores(1.0)\n    .setTaskHeapMemoryMB(256)\n    .setTaskOffHeapMemory(MemorySize.ofMebiBytes(64))\n    .build();","handlingStrategy":"validation","validationCode":"boolean anyResource = cpuCores != null || taskHeap != null || offHeap != null || managed != null || !ext.isEmpty();\nboolean mandatory = cpuCores != null && taskHeap != null;\nif (anyResource && !mandatory) throw new IllegalStateException(\"Set both setCpuCores and setTaskHeapMemory, or no resource at all\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize SlotSharingGroup construction in one factory enforcing the all-or-nothing rule.","Always pair setCpuCores with setTaskHeapMemory(MB).","If only optional resources were intended, omit them entirely for a name-only group."],"tags":["configuration","resource-spec","builder","validation"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}