apache/beam · error · IllegalStateException

No code generation strategy available

Error message

No code generation strategy available  

What it means

ByteBuddyUtils.getClassLoadingStrategy resolves a ByteBuddy ClassLoadingStrategy to generate proxy/collection classes at runtime. On JDK 9+, it tries MethodHandles.privateLookupIn to load classes into the target class's module via a private Lookup; if any reflective step fails (method missing, IllegalAccessException, etc.) it wraps the failure in this IllegalStateException. It means the JVM environment does not permit ByteBuddy to install a class-loading mechanism for the target class.

Source

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

    // Use a Lookup-based strategy for user classes for compatibility with Java 17+, but use
    // a legacy strategy to allow proxying some built-in JDK classes (e.g. interfaces, public
    // abstract classes) since we don't have permissions to get a private lookup for the
    // java.base module
    boolean systemClass = classLoader == null;
    if (ClassInjector.UsingLookup.isAvailable() && !systemClass) {
      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. Ensure the target module opens its packages to the caller (add --add-opens / --add-reads JVM flags for the module containing targetClass)
  2. Upgrade byte-buddy to a version supporting the current JDK (1.9+ for Java 11)
  3. Verify the JDK version matches Beam's supported Java versions; pin to Java 8 or 11/17 as documented
  4. Check for a SecurityManager or custom classloader policy blocking MethodHandles private lookup

Example fix

// before
java --add-reads=foo.module=ALL-UNNAMED
// error: No code generation strategy available
class foo.module { ... }
// after
java --add-reads=foo.module=ALL-UNNAMED --add-opens=foo.module/org.example=ALL-UNNAMED
class foo.module { ... }
Defensive patterns

Strategy: validation

Validate before calling

static boolean canGenerateClasses(Class<?> target) {
  return ClassInjector.UsingReflection.isAvailable()
      || MethodHandles.lookup().lookupClass().getModule()
         .canRead(target.getModule());
}

Prevention

When it happens

Trigger: Running on Java 9+ where MethodHandles.privateLookupIn is unavailable or rejects the call (targetClass's module does not open/read to the caller's module), or the reflection lookup for the methodHandles methods throws ReflectiveOperationException while handling a collection transform (e.g. via createCollectionTransformFunction).

Common situations: Upgrading Beam from Java 8 to Java 9+ runtimes with strong encapsulation (JPMS); running with a SecurityManager or restricted classloader; using ByteBuddy versions incompatible with the JDK; embedding Beam in an application server with module restrictions.

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/98d6c587345390d5. Report an issue: GitHub.