elastic/elasticsearch · error · UnsupportedOperationException

Operating system {}

Error message

Operating system {}

What it means

UnsupportedOperationException from the Java toolchain resolver's OS-name mapping. The switch in toOsString() only handles MAC_OS, LINUX, and WINDOWS; any other OperatingSystem enum value falls to default and throws.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/toolchain/AbstractCustomJavaToolchainResolver.java:28

package org.elasticsearch.gradle.internal.toolchain;

import org.gradle.jvm.toolchain.JavaToolchainResolver;
import org.gradle.jvm.toolchain.JvmVendorSpec;
import org.gradle.platform.Architecture;
import org.gradle.platform.OperatingSystem;

abstract class AbstractCustomJavaToolchainResolver implements JavaToolchainResolver {

    static String toOsString(OperatingSystem operatingSystem) {
        return toOsString(operatingSystem, null);
    }

    static String toOsString(OperatingSystem operatingSystem, JvmVendorSpec v) {
        return switch (operatingSystem) {
            case MAC_OS -> (v == null || v.equals(JvmVendorSpec.ADOPTIUM) == false) ? "macos" : "mac";
            case LINUX -> "linux";
            case WINDOWS -> "windows";
            default -> throw new UnsupportedOperationException("Operating system " + operatingSystem);
        };
    }

    static String toArchString(Architecture architecture) {
        return switch (architecture) {
            case X86_64 -> "x64";
            case AARCH64 -> "aarch64";
            case X86 -> "x86";
            default -> throw new UnsupportedOperationException("Architecture " + architecture);
        };
    }

    protected static boolean anyVendorOr(JvmVendorSpec givenVendor, JvmVendorSpec expectedVendor) {
        return givenVendor.matches("any") || givenVendor.equals(expectedVendor);
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Confirm the host operating system is one of macOS, Linux, or Windows.
  2. If a new OS constant legitimately needs support, add an explicit case branch returning its download-path string.
  3. Pin Gradle to a version whose OperatingSystem enum matches the resolver's expectations.

Example fix

// before
case WINDOWS -> "windows";
default -> throw new UnsupportedOperationException("Operating system " + operatingSystem);

// after
case WINDOWS -> "windows";
case FREE_BSD -> "freebsd";
default -> throw new UnsupportedOperationException("Operating system " + operatingSystem);
Defensive patterns

Strategy: validation

Validate before calling

Set<OperatingSystem> supported = EnumSet.of(OperatingSystem.MAC_OS, OperatingSystem.LINUX, OperatingSystem.WINDOWS);
if (!supported.contains(operatingSystem)) {
    throw new IllegalStateException("Unsupported OS for custom toolchain: " + operatingSystem);
}

Type guard

static boolean isOsSupported(OperatingSystem os) {
    return os == OperatingSystem.MAC_OS || os == OperatingSystem.LINUX || os == OperatingSystem.WINDOWS;
}

Prevention

When it happens

Trigger: Gradle reports an OperatingSystem value outside the three supported ones (e.g. a future Gradle release adding FREE_BSD, SOLARIS, or an UNKNOWN generic type) when resolving a custom JDK toolchain.

Common situations: Running the build on an unusual host OS; upgrading Gradle to a version that introduced a new OperatingSystem enum constant; a test faking an unsupported OS.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/09ef675c082282d6. Report an issue: GitHub.