apache/flink · critical · IllegalStateException

Cannot retrieve platform classloader on Java 9+

Error message

Cannot retrieve platform classloader on Java 9+

What it means

Thrown during ComponentClassLoader static initialization if invoking ClassLoader.getPlatformClassLoader() via reflection throws an unexpected exception (not NoSuchMethodException, which is tolerated for Java 8). This means the JVM claims to be Java 9+ but the platform classloader method failed unexpectedly.

Source

Thrown at flink-core/src/main/java/org/apache/flink/core/classloading/ComponentClassLoader.java:297

    // ----------------------------------------------------------------------------------------------

    private static String[] convertPackagePrefixesToPathPrefixes(String[] packagePrefixes) {
        return Arrays.stream(packagePrefixes)
                .map(packageName -> packageName.replace('.', '/'))
                .toArray(String[]::new);
    }

    static {
        ClassLoader platformLoader = null;
        try {
            platformLoader =
                    (ClassLoader)
                            ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
        } catch (NoSuchMethodException e) {
            // on Java 8 this method does not exist, but using null indicates the bootstrap
            // loader that we want to have
        } catch (Exception e) {
            throw new IllegalStateException("Cannot retrieve platform classloader on Java 9+", e);
        }
        PLATFORM_OR_BOOTSTRAP_LOADER = platformLoader;
        ClassLoader.registerAsParallelCapable();
    }
}

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Use a standard, certified JDK (Temurin, Corretto, OpenJDK) at a supported version (11, 17, or 21).
  2. If a security manager is in play, grant reflect permission for ClassLoader methods.
  3. Reinstall or switch the JDK to eliminate a corrupted runtime.
Defensive patterns

Strategy: validation

Validate before calling

String spec = System.getProperty("java.specification.version");
if (Integer.parseInt(spec.split("\\.")[0]) >= 9) {
    try {
        ClassLoader.class.getMethod("getPlatformClassLoader").invoke(null);
    } catch (Exception e) {
        throw new IllegalStateException("JVM does not support getPlatformClassLoader", e);
    }
}

Prevention

When it happens

Trigger: Running on a non-standard or broken JVM where getPlatformClassLoader exists but throws. Extremely rare; the static initializer catches NoSuchMethodException for Java 8 but rethrows other reflective invocation failures.

Common situations: Corrupted or non-compliant JVM installation. Custom JVM forks that don't fully implement the Java 9+ ClassLoader API. Security manager blocking reflective access to ClassLoader internals.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/01ed0403c6ae3619. Report an issue: GitHub.