apache/beam · error · IllegalStateException

No code generation strategy available

Error message

No code generation strategy available

What it means

This is the terminal fallback in getClassLoadingStrategy: when neither MethodHandles.privateLookupIn-based loading applies nor ByteBuddy's reflection-based ClassInjector (ClassInjector.UsingReflection) is available, there is no way to load generated classes, so the method throws IllegalStateException. It indicates the runtime JVM blocks all ByteBuddy class-injection mechanisms.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/util/ByteBuddyUtils.java:59

      try {
        Class<?> methodHandles = Class.forName("java.lang.invoke.MethodHandles", true, classLoader);
        @SuppressWarnings("nullness") // MethodHandles#lookup accepts null
        Object lookup = methodHandles.getMethod("lookup").invoke(null);
        Class<?> lookupClass =
            Class.forName("java.lang.invoke.MethodHandles$Lookup", true, classLoader);
        Method privateLookupIn =
            methodHandles.getMethod("privateLookupIn", Class.class, lookupClass);
        @SuppressWarnings("nullness") // this is a static method, the receiver can be null
        Object privateLookup = requireNonNull(privateLookupIn.invoke(null, targetClass, lookup));
        strategy = ClassLoadingStrategy.UsingLookup.of(requireNonNull(privateLookup));
      } catch (ReflectiveOperationException e) {
        throw new IllegalStateException(
            "No code generation strategy available " + targetClass + " " + classLoader, e);
      }
    } else if (ClassInjector.UsingReflection.isAvailable()) {
      strategy = ClassLoadingStrategy.Default.INJECTION;
    } else {
      throw new IllegalStateException("No code generation strategy available");
    }
    return strategy;
  }
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Add JVM flag --add-opens java.base/java.lang=ALL-UNNAMED so UsingReflection becomes available
  2. Upgrade the byte-buddy dependency to the latest version compatible with your JDK
  3. Run on a JDK version officially supported by the Beam release
  4. Check that ClassInjector.UsingReflection.isAvailable() passes in a smoke test before deploying

Example fix

// before
java -jar pipeline.jar
// IllegalStateException: No code generation strategy available
// after
java --add-opens java.base/java.lang=ALL-UNNAMED -jar pipeline.jar
Defensive patterns

Strategy: validation

Validate before calling

if (!ClassInjector.UsingReflection.isAvailable()) {
  throw new IllegalStateException(
      "Add --add-opens java.base/java.lang=ALL-UNNAMED to JVM args");
}

Prevention

When it happens

Trigger: Running on a JDK where ClassInjector.UsingReflection.isAvailable() returns false (Java 9+ with strong encapsulation where reflection into JDK class loaders is blocked) and no lookup-based strategy was obtainable.

Common situations: Running Beam on Java 16+ without --add-opens java.base/java.lang=ALL-UNNAMED; container images with hardened JDKs; using outdated ByteBuddy versions on new JDKs.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/ce32a64ea93f9d41. Report an issue: GitHub.