{"record":{"id":"d15b6647e95109e1","repo":"apache/flink","slug":"the-cpu-cores-and-task-heap-memory-are-required-wh","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":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/operators/SlotSharingGroup.java","lineNumber":163,"sourceCode":"            MemorySize taskOffHeapMemory =\n                    group.getTaskOffHeapMemory() == null\n                            ? MemorySize.ZERO\n                            : group.getTaskOffHeapMemory();\n            MemorySize managedMemory =\n                    group.getManagedMemory() == null ? MemorySize.ZERO : group.getManagedMemory();\n            return new SlotSharingGroup(\n                    group.getName(),\n                    new CPUResource(group.getCpuCores()),\n                    group.getTaskHeapMemory(),\n                    taskOffHeapMemory,\n                    managedMemory,\n                    group.getExternalResources());\n        } else if (group.getCpuCores() != null\n                || group.getTaskHeapMemory() != null\n                || group.getTaskOffHeapMemory() != null\n                || group.getManagedMemory() != null\n                || !group.getExternalResources().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(group.getName());\n        }\n    }\n\n    /** Builder for the {@link SlotSharingGroup}. */\n    public static class Builder {\n\n        private String name;\n        private CPUResource cpuCores;\n        private MemorySize taskHeapMemory;\n        private MemorySize taskOffHeapMemory;\n        private MemorySize managedMemory;\n        private Map<String, Double> externalResources = new HashMap<>();\n\n        private Builder(String name) {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/operators/SlotSharingGroup.java#L145-L181","documentation":"Thrown by SlotSharingGroup.from(org.apache.flink.api.common.SlotSharingGroup) when the source group has some resource components set (cpuCores, taskHeapMemory, taskOffHeapMemory, managedMemory, or externalResources) but not both of the two mandatory fields: cpuCores AND taskHeapMemory. These two are required because a slot sharing group cannot be partially specified — either all critical resources are configured, or none are (yielding an unnamed/default group).","triggerScenarios":"Calling SlotSharingGroup.from(apiGroup) where apiGroup was constructed with e.g. only setCpuCores(2.0) but not setTaskHeapMemory(), or vice versa. Setting taskOffHeapMemory or externalResources without setting cpuCores and taskHeapMemory first.","commonSituations":"Programmatically building a SlotSharingGroupConfiguration via SlotSharingGroupUtils or the REST API with partial resource settings. Migrating from older Flink versions where partial resource specs were tolerated. Configuring external resources (GPUs) without also specifying cpu and heap.","solutions":["Always set both setCpuCores() and setTaskHeapMemory() on the source SlotSharingGroup before calling SlotSharingGroup.from().","If you only need a name (no custom resources), leave all resource fields null — from() will create a name-only group.","Set taskOffHeapMemory and managedMemory only after cpuCores and taskHeapMemory are both non-null.","Audit your SlotSharingGroupConfiguration builder calls to ensure the mandatory pair is always set together."],"exampleFix":"// before\nSlotSharingGroupConfiguration config = SlotSharingGroupConfiguration.newBuilder(\"my-group\")\n    .setCpuCores(2.0)\n    .build();\n// missing taskHeapMemory -> from() throws\n\n// after\nSlotSharingGroupConfiguration config = SlotSharingGroupConfiguration.newBuilder(\"my-group\")\n    .setCpuCores(2.0)\n    .setTaskHeapMemory(MemorySize.ofMebiBytes(512))\n    .build();","handlingStrategy":"validation","validationCode":"void validateSlotSharingGroup(org.apache.flink.api.common.SlotSharingGroup group) {\n    boolean hasCpu = group.getCpuCores() != null;\n    boolean hasHeap = group.getTaskHeapMemory() != null;\n    boolean hasAny = hasCpu || hasHeap\n        || group.getTaskOffHeapMemory() != null\n        || group.getManagedMemory() != null\n        || !group.getExternalResources().isEmpty();\n    if (hasAny && !(hasCpu && hasHeap)) {\n        throw new IllegalArgumentException(\"cpuCores and taskHeapMemory must both be set if any resource is specified\");\n    }\n}","typeGuard":"boolean isFullySpecified(org.apache.flink.api.common.SlotSharingGroup group) {\n    return group.getCpuCores() != null && group.getTaskHeapMemory() != null;\n}","tryCatchPattern":"try {\n    SlotSharingGroup ssg = SlotSharingGroup.from(apiGroup);\n} catch (IllegalArgumentException e) {\n    // cpuCores or taskHeapMemory was missing while other resources were set\n    throw new RuntimeException(\"Invalid SlotSharingGroup: \" + e.getMessage(), e);\n}","preventionTips":["Always set both setCpuCores and setTaskHeapMemory together on SlotSharingGroupConfiguration.","If setting external resources (GPU), ensure cpu and heap are set first.","Create a builder utility that enforces the mandatory pair."],"tags":["slot-sharing-group","resource-configuration","validation","flink-core"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}