apache/flink · error · IllegalArgumentException
The cpu cores and task heap memory are required when specify
Error message
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.
What it means
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.
Source
Thrown at flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java:229
/** Build the SlotSharingGroup. */
public SlotSharingGroup build() {
if (cpuCores != null && taskHeapMemory != null) {
taskOffHeapMemory = Optional.ofNullable(taskOffHeapMemory).orElse(MemorySize.ZERO);
managedMemory = Optional.ofNullable(managedMemory).orElse(MemorySize.ZERO);
return new SlotSharingGroup(
name,
cpuCores,
taskHeapMemory,
taskOffHeapMemory,
managedMemory,
externalResources);
} else if (cpuCores != null
|| taskHeapMemory != null
|| taskOffHeapMemory != null
|| managedMemory != null
|| !externalResources.isEmpty()) {
throw new IllegalArgumentException(
"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.");
} else {
return new SlotSharingGroup(name);
}
}
}
}
View on GitHub (pinned to 2f3c205e92)
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.
Example fix
// before
SlotSharingGroup.newBuilder("g")
.setTaskOffHeapMemory(MemorySize.ofMebiBytes(64))
.build(); // throws: cpuCores/taskHeapMemory missing
// after
SlotSharingGroup.newBuilder("g")
.setCpuCores(1.0)
.setTaskHeapMemoryMB(256)
.setTaskOffHeapMemory(MemorySize.ofMebiBytes(64))
.build(); Defensive patterns
Strategy: validation
Validate before calling
boolean anyResource = cpuCores != null || taskHeap != null || offHeap != null || managed != null || !ext.isEmpty();
boolean mandatory = cpuCores != null && taskHeap != null;
if (anyResource && !mandatory) throw new IllegalStateException("Set both setCpuCores and setTaskHeapMemory, or no resource at all"); Prevention
- 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.
When it happens
Trigger: Calling build() after setting e.g. setManagedMemory(...) or setTaskOffHeapMemory(...) but omitting setCpuCores or setTaskHeapMemory; or setting only setCpuCores without heap memory.
Common situations: 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.
Related errors
- The cpu cores should be positive.
- At least one trigger condition must be configured.
- The task heap memory should be positive.
- The jarFile and entryPointClassName can not be null at the s
- Not allowed configuration change(s) were detected:\n - {erro
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/6c5d74d42bf9d767.
Report an issue: GitHub.