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
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).
Source
Thrown at flink-core/src/main/java/org/apache/flink/api/common/operators/SlotSharingGroup.java:163
MemorySize taskOffHeapMemory =
group.getTaskOffHeapMemory() == null
? MemorySize.ZERO
: group.getTaskOffHeapMemory();
MemorySize managedMemory =
group.getManagedMemory() == null ? MemorySize.ZERO : group.getManagedMemory();
return new SlotSharingGroup(
group.getName(),
new CPUResource(group.getCpuCores()),
group.getTaskHeapMemory(),
taskOffHeapMemory,
managedMemory,
group.getExternalResources());
} else if (group.getCpuCores() != null
|| group.getTaskHeapMemory() != null
|| group.getTaskOffHeapMemory() != null
|| group.getManagedMemory() != null
|| !group.getExternalResources().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(group.getName());
}
}
/** Builder for the {@link SlotSharingGroup}. */
public static class Builder {
private String name;
private CPUResource cpuCores;
private MemorySize taskHeapMemory;
private MemorySize taskOffHeapMemory;
private MemorySize managedMemory;
private Map<String, Double> externalResources = new HashMap<>();
private Builder(String name) {View on GitHub (pinned to 2f3c205e92)
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.
Example fix
// before
SlotSharingGroupConfiguration config = SlotSharingGroupConfiguration.newBuilder("my-group")
.setCpuCores(2.0)
.build();
// missing taskHeapMemory -> from() throws
// after
SlotSharingGroupConfiguration config = SlotSharingGroupConfiguration.newBuilder("my-group")
.setCpuCores(2.0)
.setTaskHeapMemory(MemorySize.ofMebiBytes(512))
.build(); Defensive patterns
Strategy: validation
Validate before calling
void validateSlotSharingGroup(org.apache.flink.api.common.SlotSharingGroup group) {
boolean hasCpu = group.getCpuCores() != null;
boolean hasHeap = group.getTaskHeapMemory() != null;
boolean hasAny = hasCpu || hasHeap
|| group.getTaskOffHeapMemory() != null
|| group.getManagedMemory() != null
|| !group.getExternalResources().isEmpty();
if (hasAny && !(hasCpu && hasHeap)) {
throw new IllegalArgumentException("cpuCores and taskHeapMemory must both be set if any resource is specified");
}
} Type guard
boolean isFullySpecified(org.apache.flink.api.common.SlotSharingGroup group) {
return group.getCpuCores() != null && group.getTaskHeapMemory() != null;
} Try / catch
try {
SlotSharingGroup ssg = SlotSharingGroup.from(apiGroup);
} catch (IllegalArgumentException e) {
// cpuCores or taskHeapMemory was missing while other resources were set
throw new RuntimeException("Invalid SlotSharingGroup: " + e.getMessage(), e);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The output size cannot be smaller than zero.
- The output cardinality cannot be smaller than zero.
- The size of produced records must be positive.
- The filter factor cannot be smaller than zero.
- Return type {keyType} of KeySelector {keyExtractor.getClass(
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/d15b6647e95109e1.
Report an issue: GitHub.