apache/flink · error · IllegalArgumentException
The cpu cores should be positive.
Error message
The cpu cores should be positive.
What it means
SlotSharingGroup.Builder.setPassword-style validation: setCpuCores(double) rejects values <= 0 with this IllegalArgumentException, because a slot sharing group's resource spec must declare a strictly positive CPU share. Zero or negative cores would make the group unschedulable, so the builder fails fast.
Source
Thrown at flink-core-api/src/main/java/org/apache/flink/api/common/SlotSharingGroup.java:155
/** Builder for {@link SlotSharingGroup}. */
@Experimental
public static class Builder {
private final String name;
private Double cpuCores;
private MemorySize taskHeapMemory;
private MemorySize taskOffHeapMemory;
private MemorySize managedMemory;
private final Map<String, Double> externalResources = new HashMap<>();
private Builder(String name) {
this.name = name;
}
/** Set the CPU cores for this SlotSharingGroup. */
public Builder setCpuCores(double cpuCores) {
if (cpuCores <= 0) {
throw new IllegalArgumentException("The cpu cores should be positive.");
}
this.cpuCores = cpuCores;
return this;
}
/** Set the task heap memory for this SlotSharingGroup. */
public Builder setTaskHeapMemory(MemorySize taskHeapMemory) {
if (taskHeapMemory.compareTo(MemorySize.ZERO) <= 0) {
throw new IllegalArgumentException("The task heap memory should be positive.");
}
this.taskHeapMemory = taskHeapMemory;
return this;
}
/** Set the task heap memory for this SlotSharingGroup in MB. */
public Builder setTaskHeapMemoryMB(int taskHeapMemoryMB) {
if (taskHeapMemoryMB <= 0) {
throw new IllegalArgumentException("The task heap memory should be positive.");View on GitHub (pinned to 2f3c205e92)
Solutions
- Set a positive value, e.g. setCpuCores(1.0) or a fraction like 0.5.
- Validate derived values before building: if the computed cores are <= 0, fall back to a documented default.
- Check the option's docs for minimum supported values.
Example fix
// before
.newBuilder("group").setCpuCores(totalCores - reservedCores) // 0.0 when fully reserved
// after
.newBuilder("group").setCpuCores(Math.max(totalCores - reservedCores, 0.1)) Defensive patterns
Strategy: validation
Validate before calling
if (!(cpuCores > 0)) throw new IllegalArgumentException("cpuCores must be > 0, got " + cpuCores);
SlotSharingGroup.newBuilder(name).setCpuCores(cpuCores); Prevention
- Default cpuCores to a positive value (e.g. 1.0) in config plumbing.
- Clamp computed cores with Math.max(value, minimum).
- Validate resource values at the config boundary, not inside builders.
When it happens
Trigger: Calling SlotSharingGroup.newBuilder(name).setCpuCores(0), setCpuCores(-1), or passing a computed value (e.g. totalCores - reserved) that evaluates to 0 or negative.
Common situations: Deriving cpuCores from environment variables or fractions of TaskManager slots that round to zero; configuration templates defaulting to 0 meaning 'unset'; arithmetic that subtracts too much.
Related errors
- The cpu cores and task heap memory are required when specify
- 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/be7dbb6b00a8a56f.
Report an issue: GitHub.