{"record":{"id":"80c89f6dda733e26","repo":"apache/druid","slug":"unable-to-define-specialized-class","errorCode":null,"errorMessage":"Unable to define specialized class: ","messagePattern":"Unable to define specialized class: ","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"critical","filePath":"processing/src/main/java/org/apache/druid/java/util/common/DefineClassUtils.java","lineNumber":107,"sourceCode":"  public static Class defineClass(\n      Class<?> targetClass,\n      byte[] byteCode,\n      String className\n  )\n  {\n    if (DEFINE_CLASS == null) {\n      throw new UnsupportedOperationException(\n          \"defineClass is not supported on this platform, \"\n          + \"because internal Java APIs are not compatible with this Druid version\",\n          DEFINE_CLASS_NOT_SUPPORTED_EXCEPTION\n      );\n    }\n\n    try {\n      return (Class) DEFINE_CLASS.invokeExact(targetClass, byteCode, className);\n    }\n    catch (Throwable t) {\n      throw new UnsupportedOperationException(\"Unable to define specialized class: \" + className, t);\n    }\n  }\n}\n","sourceCodeStart":89,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/DefineClassUtils.java#L89-L111","documentation":"DefineClassUtils.defineClass invokes the cached JDK internal defineClass MethodHandle with invokeExact. If the invocation itself fails for any reason ( IllegalAccess, IllegalCallerException, LinkageError, class file errors), it wraps the cause in an UnsupportedOperationException with this message.","triggerScenarios":"DEFINE_CLASS.invokeExact(targetClass, byteCode, className) throws a Throwable — e.g. the caller module lacks the lookup/access rights, the bytecode is invalid, a LinkageError occurs, or the JVM restricts defineClass even though the handle exists.","commonSituations":"Running on JDK 9+ without --add-opens/--add-exports for internal APIs; defining a class into a package that is not open to Druid's module; malformed generated bytecode.","solutions":["Read the cause ('Caused by') to identify whether it is access control or bytecode corruption","Add the required JVM flags (e.g. --add-opens java.base/java.lang=ALL-UNNAMED) when running on JDK 9+","Ensure the target class's package is opened/exported to the Druid module performing the definition","Verify the generated bytecode matches the target class's classloader/version expectations"],"exampleFix":"// JVM launch flags\n// before: java -jar druid.jar\n// after:  java --add-opens java.base/java.lang=ALL-UNNAMED -jar druid.jar","handlingStrategy":"try-catch","validationCode":"// preflight: attempt resolving the internal API\n// (no public precheck besides isDefineClassSupported)\nboolean handleResolvable = DefineClassUtils.isDefineClassSupported();","typeGuard":null,"tryCatchPattern":"try {\n  return DefineClassUtils.defineClass(targetClass, byteCode, className);\n} catch (UnsupportedOperationException e) {\n  Throwable cause = e.getCause();\n  log.error(e, \"defineClass invoke failed: %s\", cause == null ? \"unknown\" : cause.getClass());\n  throw new RuntimeException(\"Class definition failed; check --add-opens flags\", e);\n}","preventionTips":["Launch with --add-opens java.base/java.lang=ALL-UNNAMED on JDK 9+","Keep target packages open to Druid's module","Validate generated bytecode in tests before runtime definition","Test on the exact JVM version used in production"],"tags":["reflection","jdk-compatibility","class-loading"],"backgroundTag":"unsupported-platform","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}