{"record":{"id":"2e1e64359da18700","repo":"apache/druid","slug":"vm-maxdirectmemory-doesn-t-exist-cannot-do-memory","errorCode":null,"errorMessage":"VM.maxDirectMemory doesn't exist, cannot do memory check.","messagePattern":"VM\\.maxDirectMemory doesn't exist, cannot do memory check\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/utils/RuntimeInfo.java","lineNumber":66,"sourceCode":"  }\n\n  public long getDirectMemorySizeBytes()\n  {\n    try {\n      Class<?> vmClass = Class.forName(\"jdk.internal.misc.VM\");\n      Object maxDirectMemoryObj = vmClass.getMethod(\"maxDirectMemory\").invoke(null);\n\n      if (maxDirectMemoryObj == null || !(maxDirectMemoryObj instanceof Number)) {\n        throw new UOE(\"Cannot determine maxDirectMemory from [%s]\", maxDirectMemoryObj);\n      } else {\n        return ((Number) maxDirectMemoryObj).longValue();\n      }\n    }\n    catch (ClassNotFoundException e) {\n      throw new UnsupportedOperationException(\"No VM class, cannot do memory check.\", e);\n    }\n    catch (NoSuchMethodException e) {\n      throw new UnsupportedOperationException(\"VM.maxDirectMemory doesn't exist, cannot do memory check.\", e);\n    }\n    catch (InvocationTargetException e) {\n      throw new UnsupportedOperationException(\"static method shouldn't throw this\", e);\n    }\n    catch (IllegalAccessException e) {\n      throw new UnsupportedOperationException(\"public method, shouldn't throw this\", e);\n    }\n  }\n}\n","sourceCodeStart":48,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/utils/RuntimeInfo.java#L48-L76","documentation":"Thrown by RuntimeInfo.getDirectMemorySizeBytes when the reflective lookup of jdk.internal.misc.VM.maxDirectMemory() throws NoSuchMethodException - the VM class exists but has no such method in this JDK build. Wrapped in UnsupportedOperationException because direct-memory introspection is unavailable.","triggerScenarios":"Calling getDirectMemorySizeBytes() (directly or via maxDirectMemory, Memory, buffer init, MM/Peon tuning) on JDK builds where the internal VM class does not declare maxDirectMemory(), e.g. some vendor JDKs,GraalVM, or future JDK releases that removed/renamed the internal API.","commonSituations":"Upgrading to a JDK version that reshuffled JDK-internal APIs, running on GraalVM or vendor-distinct JDKs, using a JRE image that omitted internal classes' methods.","solutions":["Pin Druid to a JDK version whose internals Druid supports (check Druid's tested JDK matrix)","Set -XX:MaxDirectMemorySize and rely on Druid config (druid.processing.buffer.directSize or derived settings) rather than runtime introspection","Check for a newer Druid version with updated reflective lookup for your JDK"],"exampleFix":"// before (Dockerfile)\nFROM ghcr.io/graalvm/jdk:latest\n// after\nFROM eclipse-temurin:17-jre","handlingStrategy":"try-catch","validationCode":"boolean methodAvailable;\ntry {\n  Class.forName(\"jdk.internal.misc.VM\").getMethod(\"maxDirectMemory\");\n  methodAvailable = true;\n} catch (ReflectiveOperationException e) { methodAvailable = false; }","typeGuard":"static boolean hasMaxDirectMemoryMethod() {\n  try {\n    Class.forName(\"jdk.internal.misc.VM\").getMethod(\"maxDirectMemory\");\n    return true;\n  } catch (ReflectiveOperationException e) { return false; }\n}","tryCatchPattern":"try {\n  long direct = runtimeInfo.getMaxDirectMemory();\n} catch (UnsupportedOperationException e) {\n  long direct = Long.getLong(\"druid.processing.buffer.directSize\", defaultDirect);\n}","preventionTips":["Pin to a JDK version Druid has tested (avoid bleeding-edge or vendor-reshuffled internals)","Set explicit direct memory config so JVM-introspection is only an optimization","Check Druid release notes when upgrading the JDK"],"tags":["jvm","reflection","memory"],"backgroundTag":"class-not-found","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"}