{"record":{"id":"a2e9f83971d2ea3f","repo":"apache/druid","slug":"no-vm-class-cannot-do-memory-check","errorCode":null,"errorMessage":"No VM class, cannot do memory check.","messagePattern":"No VM class, cannot do memory check\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/utils/RuntimeInfo.java","lineNumber":63,"sourceCode":"  public long getFreeHeapSizeBytes()\n  {\n    return Runtime.getRuntime().freeMemory();\n  }\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":45,"sourceCodeEnd":76,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/utils/RuntimeInfo.java#L45-L76","documentation":"Thrown by RuntimeInfo.getDirectMemorySizeBytes when Class.forName(\"jdk.internal.misc.VM\") fails with ClassNotFoundException, meaning the current JVM does not expose the JDK-internal VM class. Wrapped in UnsupportedOperationException because Druid cannot introspect direct memory on such a runtime.","triggerScenarios":"Calling getDirectMemorySizeBytes() (via maxDirectMemory, Memory, buffer init, or MiddleManager/Indexer tuning) on a JVM lacking jdk.internal.misc.VM - notably Java 8, where the class lives in sun.misc.VM instead, or other non-OpenJDK runtimes.","commonSituations":"Running Druid on Java 8 or an unsupported JVM distribution, container images with stripped/down-level JDKs, switching JDK vendors without checking Druid's supported matrix.","solutions":["Use a supported JDK (Java 11+ OpenJDK/HotSpot) where jdk.internal.misc.VM exists","As a workaround on Java 8, set druid.processing buffer/direct size config explicitly instead of relying on runtime detection","Verify the runtime JDK with java -version and switch container base images accordingly"],"exampleFix":"// before\nFROM openjdk:8-jre\n// after\nFROM eclipse-temurin:11-jre","handlingStrategy":"try-catch","validationCode":"boolean vmClassAvailable;\ntry { Class.forName(\"jdk.internal.misc.VM\"); vmClassAvailable = true; }\ncatch (ClassNotFoundException e) { vmClassAvailable = false; }\nif (!vmClassAvailable) { /* use config-based direct memory instead */ }","typeGuard":"static boolean supportsVmIntrospection() {\n  try { Class.forName(\"jdk.internal.misc.VM\"); return true; }\n  catch (ClassNotFoundException e) { return false; }\n}","tryCatchPattern":"try {\n  long direct = runtimeInfo.getMaxDirectMemory();\n} catch (UnsupportedOperationException e) {\n  log.warn(\"No VM class on this JDK ({}), using configured direct size\", e.getCause());\n  long direct = configuredDirectSize;\n}","preventionTips":["Verify the JDK meets Druid's supported matrix (Java 11+ HotSpot)","Avoid Java 8 / non-OpenJDK runtimes; use eclipse-temurin or equivalent images","Provide explicit -XX:MaxDirectMemorySize so introspection failure is non-fatal"],"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"}