apache/druid · critical · java.lang.UnsupportedOperationException
Unable to define specialized class:
Error message
Unable to define specialized class:
What it means
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.
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
Example fix
// JVM launch flags // before: java -jar druid.jar // after: java --add-opens java.base/java.lang=ALL-UNNAMED -jar druid.jar
Defensive patterns
Strategy: try-catch
Validate before calling
// preflight: attempt resolving the internal API // (no public precheck besides isDefineClassSupported) boolean handleResolvable = DefineClassUtils.isDefineClassSupported();
Try / catch
try {
return DefineClassUtils.defineClass(targetClass, byteCode, className);
} catch (UnsupportedOperationException e) {
Throwable cause = e.getCause();
log.error(e, "defineClass invoke failed: %s", cause == null ? "unknown" : cause.getClass());
throw new RuntimeException("Class definition failed; check --add-opens flags", e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- DEFINE_CLASS_NOT_SUPPORTED_EXCEPTION
- Cannot determine maxDirectMemory from
- CLEANER_NOT_SUPPORTED_EXCEPTION
- Cleaning is not support on this platform, because internal…
- No VM class, cannot do memory check.
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/80c89f6dda733e26.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/java/util/common/DefineClassUtils.java:107
public static Class defineClass(
Class<?> targetClass,
byte[] byteCode,
String className
)
{
if (DEFINE_CLASS == null) {
throw new UnsupportedOperationException(
"defineClass is not supported on this platform, "
+ "because internal Java APIs are not compatible with this Druid version",
DEFINE_CLASS_NOT_SUPPORTED_EXCEPTION
);
}
try {
return (Class) DEFINE_CLASS.invokeExact(targetClass, byteCode, className);
}
catch (Throwable t) {
throw new UnsupportedOperationException("Unable to define specialized class: " + className, t);
}
}
}
View on GitHub (pinned to 9b90983fd2)