GoogleContainerTools/jib · error · IllegalArgumentException

platforms set cannot be empty

Error message

platforms set cannot be empty

What it means

ContainerBuildPlan.Builder.setPlatforms() requires a non-empty set of Platform entries for multi-platform (manifest list) builds. An empty set would leave the build plan with no target platform, so it throws IllegalArgumentException immediately.

Source

Thrown at jib-build-plan/src/main/java/com/google/cloud/tools/jib/api/buildplan/ContainerBuildPlan.java:105

      platforms.add(new Platform(architecture, os));
      return this;
    }

    /**
     * Sets a desired platform (properties including OS and architecture) list. If the base image
     * reference is a Docker manifest list or an OCI image index, an image builder may select the
     * base images matching the given platforms. If the base image reference is an image manifest,
     * an image builder may ignore the given platforms and use the platform of the base image or may
     * decide to raise on error.
     *
     * <p>Note that a new build plan starts with "amd64/linux" as the default platform.
     *
     * @param platforms list of platforms to select base images in case of a manifest list
     * @return this
     */
    public Builder setPlatforms(Set<Platform> platforms) {
      if (platforms.isEmpty()) {
        throw new IllegalArgumentException("platforms set cannot be empty");
      }
      this.platforms = new LinkedHashSet<>(platforms);
      return this;
    }

    /**
     * Sets the container image creation time. The default is {@link Instant#EPOCH}.
     *
     * @param creationTime the container image creation time
     * @return this
     */
    public Builder setCreationTime(Instant creationTime) {
      this.creationTime = creationTime;
      return this;
    }

    /**
     * Sets the format to build the container image as. Use {@link ImageFormat#Docker} for Docker

View on GitHub (pinned to fb949e2676)

Solutions

  1. Provide at least one Platform, e.g. setPlatforms(ImmutableSet.of(Platform.builder().setArchitecture("amd64").setOs("linux").build()))
  2. Default to the current host platform when no platforms are configured
  3. Guard upstream: throw a clearer error when the configured platform list is empty

Example fix

// before
builder.setPlatforms(platforms.stream().filter(p -> p.getOs().equals("linux")).collect(Collectors.toSet())); // may be empty
// after
Set<Platform> selected = ...;
if (selected.isEmpty()) { selected = ImmutableSet.of(Platform.builder().setArchitecture("amd64").setOs("linux").build()); }
builder.setPlatforms(selected);
Defensive patterns

Strategy: validation

Validate before calling

if (platforms == null || platforms.isEmpty()) platforms = Set.of(Platform.builder().setArchitecture("amd64").setOs("linux").build());

Type guard

boolean hasPlatforms(BuildPlan plan) { return plan.getPlatforms() != null && !plan.getPlatforms().isEmpty(); }

Try / catch

try { builder.setPlatforms(platforms); } catch (IllegalArgumentException e) { builder.setPlatforms(defaultPlatforms); }

Prevention

When it happens

Trigger: Calling setPlatforms(Collections.emptySet()) or setPlatforms(new HashSet<>()) or a Set filtered down to zero entries.

Common situations: Building a build-plan JSON programmatically; computing platforms from config where an empty/missing list yields an empty set.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of GoogleContainerTools/jib@fb949e2676 (2026-09-06). Data as JSON: /api/errors/26d7f2eb25b361e3. Report an issue: GitHub.