GoogleContainerTools/jib · error · IllegalArgumentException

Platform must be of form os/architecture.

Error message

Platform must be of form os/architecture.

What it means

PlatformParameters.of parses an 'os/architecture' string into platform config for multi-image builds. The input must match the regex ([^/ ]+)/([^/ ]+) — exactly one non-space segment, a slash, and another non-space segment — otherwise it throws IllegalArgumentException that the platform must be of the form os/architecture.

Source

Thrown at jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/PlatformParameters.java:34

package com.google.cloud.tools.jib.gradle;

import com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Internal;

/** Configuration of a platform. */
public class PlatformParameters implements PlatformConfiguration {

  static PlatformParameters of(String osArchitecture) {
    Matcher matcher = Pattern.compile("([^/ ]+)/([^/ ]+)").matcher(osArchitecture);
    if (!matcher.matches()) {
      throw new IllegalArgumentException("Platform must be of form os/architecture.");
    }
    PlatformParameters platformParameters = new PlatformParameters();
    platformParameters.os = matcher.group(1);
    platformParameters.architecture = matcher.group(2);
    return platformParameters;
  }

  @Nullable private String os;
  @Nullable private String architecture;

  @Input
  @Nullable
  public String getOs() {
    return os;
  }

  @Internal
  @Override

View on GitHub (pinned to fb949e2676)

Solutions

  1. Format the value as exactly '<os>/<architecture>', e.g. 'linux/amd64'
  2. Strip surrounding spaces and ensure neither segment contains spaces
  3. Split on only the first slash if the input may contain extra segments
  4. Validate the string against ([^/ ]+)/([^/ ]+) before calling of()

Example fix

// before
PlatformParameters.of("linux amd64")
// after
PlatformParameters.of("linux/amd64")
Defensive patterns

Strategy: validation

Validate before calling

static boolean isValidPlatform(String s) {
  s ==~ /[^\/ ]+\/[^\/ ]+/  // e.g. linux/amd64
}

Type guard

static String normalizePlatform(String s) {
  def parts = s?.trim()?.split('/')
  (parts?.length == 2 && parts.every { it && !it.contains(' ') }) ? s : null
}

Try / catch

try {
  def p = PlatformParameters.of(osArch)
} catch (IllegalArgumentException e) {
  if (e.message.contains('of form os/architecture')) {
    throw new IllegalArgumentException("'${osArch}' must be '<os>/<arch>', e.g. linux/amd64")
  } else { throw e }
}

Prevention

When it happens

Trigger: Constructing platform parameters programmatically (e.g. from a string like 'linux' with no slash, 'linux/amd64/extra', or strings containing spaces like 'linux amd64') — PlatformParameters.of is called with an osArchitecture string that fails the pattern match.

Common situations: Generating jib platforms from external config/CLI flags where the separator is ',' or '-' instead of '/'; including spaces from CSV parsing; passing a full platform triple instead of os/arch pair.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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