{"record":{"id":"98d6c587345390d5","repo":"apache/beam","slug":"no-code-generation-strategy-available-bytebuddyutils","errorCode":null,"errorMessage":"No code generation strategy available  ","messagePattern":"No code generation strategy available  ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/ByteBuddyUtils.java","lineNumber":53,"sourceCode":"    // Use a Lookup-based strategy for user classes for compatibility with Java 17+, but use\n    // a legacy strategy to allow proxying some built-in JDK classes (e.g. interfaces, public\n    // abstract classes) since we don't have permissions to get a private lookup for the\n    // java.base module\n    boolean systemClass = classLoader == null;\n    if (ClassInjector.UsingLookup.isAvailable() && !systemClass) {\n      try {\n        Class<?> methodHandles = Class.forName(\"java.lang.invoke.MethodHandles\", true, classLoader);\n        @SuppressWarnings(\"nullness\") // MethodHandles#lookup accepts null\n        Object lookup = methodHandles.getMethod(\"lookup\").invoke(null);\n        Class<?> lookupClass =\n            Class.forName(\"java.lang.invoke.MethodHandles$Lookup\", true, classLoader);\n        Method privateLookupIn =\n            methodHandles.getMethod(\"privateLookupIn\", Class.class, lookupClass);\n        @SuppressWarnings(\"nullness\") // this is a static method, the receiver can be null\n        Object privateLookup = requireNonNull(privateLookupIn.invoke(null, targetClass, lookup));\n        strategy = ClassLoadingStrategy.UsingLookup.of(requireNonNull(privateLookup));\n      } catch (ReflectiveOperationException e) {\n        throw new IllegalStateException(\n            \"No code generation strategy available \" + targetClass + \" \" + classLoader, e);\n      }\n    } else if (ClassInjector.UsingReflection.isAvailable()) {\n      strategy = ClassLoadingStrategy.Default.INJECTION;\n    } else {\n      throw new IllegalStateException(\"No code generation strategy available\");\n    }\n    return strategy;\n  }\n}\n","sourceCodeStart":35,"sourceCodeEnd":64,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/ByteBuddyUtils.java#L35-L64","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the target module opens its packages to the caller (add --add-opens / --add-reads JVM flags for the module containing targetClass)","Upgrade byte-buddy to a version supporting the current JDK (1.9+ for Java 11)","Verify the JDK version matches Beam's supported Java versions; pin to Java 8 or 11/17 as documented","Check for a SecurityManager or custom classloader policy blocking MethodHandles private lookup"],"exampleFix":"// before\njava --add-reads=foo.module=ALL-UNNAMED\n// error: No code generation strategy available\nclass foo.module { ... }\n// after\njava --add-reads=foo.module=ALL-UNNAMED --add-opens=foo.module/org.example=ALL-UNNAMED\nclass foo.module { ... }","handlingStrategy":"validation","validationCode":"static boolean canGenerateClasses(Class<?> target) {\n  return ClassInjector.UsingReflection.isAvailable()\n      || MethodHandles.lookup().lookupClass().getModule()\n         .canRead(target.getModule());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pin JDK versions to Beam's supported matrix","Add --add-opens/--add-reads flags in deployment scripts, not ad hoc","Keep byte-buddy up to date with the JDK","Smoke-test class generation at startup rather than at first transform use"],"tags":["java","reflection","bytebuddy","jpms","classloading"],"backgroundTag":"unsupported-platform","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}