{"record":{"id":"1bed6ea38ca42ba5","repo":"apache/druid","slug":"sun-misc-unsafe-is-not-supported-on-this-platform","errorCode":null,"errorMessage":"sun.misc.Unsafe is not supported on this platform, because internal Java APIs are not compatible with this Druid version","messagePattern":"sun\\.misc\\.Unsafe is not supported on this platform, because internal Java APIs are not compatible with this Druid version","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/java/util/common/UnsafeUtils.java","lineNumber":67,"sourceCode":"    }\n\n    if (theUnsafe != null) {\n      UNSAFE = theUnsafe;\n      UNSAFE_CLASS = unsafeClass;\n      UNSAFE_NOT_SUPPORTED_EXCEPTION = exception;\n    } else {\n      UNSAFE_CLASS = null;\n      UNSAFE = null;\n      UNSAFE_NOT_SUPPORTED_EXCEPTION = exception;\n    }\n  }\n\n  public static Object theUnsafe()\n  {\n    if (UNSAFE != null) {\n      return UNSAFE;\n    } else {\n      throw new UnsupportedOperationException(MESSAGE, UNSAFE_NOT_SUPPORTED_EXCEPTION);\n    }\n  }\n\n  public static Class<?> theUnsafeClass()\n  {\n    if (UNSAFE_CLASS != null) {\n      return UNSAFE_CLASS;\n    } else {\n      throw new UnsupportedOperationException(MESSAGE, UNSAFE_NOT_SUPPORTED_EXCEPTION);\n    }\n  }\n}\n","sourceCodeStart":49,"sourceCodeEnd":80,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/java/util/common/UnsafeUtils.java#L49-L80","documentation":"Druid's UnsafeUtils failed to obtain an instance of sun.misc.Unsafe at class-init time (typically on JDKs where internal APIs are restricted or relocated, e.g. JDK 17+ with strong encapsulation). When code later calls UnsafeUtils.theUnsafe(), it throws UnsupportedOperationException instead of returning the Unsafe handle. It is a deliberate fail-fast so Druid does not silently run without Unsafe.","triggerScenarios":"Calling UnsafeUtils.theUnsafe() when the static UNSAFE field is null — i.e. the platform blocked sun.misc.Unsafe access during static initialization (SecurityManager denial, JDK 9+ module restrictions, non-HotSpot JVM).","commonSituations":"Upgrading Druid to a version on a newer JDK (17/21) where --add-opens flags are missing; running on IBM/OpenJ9 or Android JVMs that lack compatible sun.misc.Unsafe; embedding Druid libraries in a non-Druid app on a restricted JVM.","solutions":["Run on a HotSpot JDK where sun.misc.Unsafe is accessible, or add JVM flags such as --add-opens java.base/jdk.internal.misc=ALL-UNNAMED and any needed --add-exports for the Druid version in use","Check the chained cause (UNSAFE_NOT_SUPPORTED_EXCEPTION) logged at startup to see why Unsafe acquisition failed and fix that root cause","Upgrade Druid to a release that no longer requires sun.misc.Unsafe on your JDK version","If Unsafe is genuinely unavailable in your environment, avoid code paths that call UnsafeUtils.theUnsafe() or vendor a patched UnsafeUtils"],"exampleFix":"// before (JDK 17 startup)\njava -jar druid.jar\n// after\njava --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/jdk.internal.ref=ALL-UNNAMED --add-exports java.base/jdk.internal.misc=ALL-UNNAMED -jar druid.jar","handlingStrategy":"try-catch","validationCode":"// Check JVM compatibility before relying on Unsafe-dependent paths\nboolean unsafeUsable = \"HotSpot\".equalsIgnoreCase(System.getProperty(\"java.vm.name\").replaceAll(\".*HotSpot.*\", \"HotSpot\"))\n    && !System.getProperty(\"java.specification.version\").matches(\"(1[7-9]|[2-9][0-9]).*\") ; // adjust to Druid's supported range","typeGuard":null,"tryCatchPattern":"try {\n  Object unsafe = UnsafeUtils.theUnsafe();\n  // use unsafe\n} catch (UnsupportedOperationException e) {\n  // fall back to non-Unsafe implementation or fail fast with guidance\n  log.warn(e, \"sun.misc.Unsafe unavailable; falling back\");\n}","preventionTips":["Pin JVM flags (--add-opens/--add-exports) required by your Druid version in startup scripts and containers","Standardize on a HotSpot JDK tested with your Druid version","Read the chained root-cause exception logged at startup rather than only the message","Keep Druid and JDK versions on the officially supported compatibility matrix"],"tags":["jvm","unsupported-platform","reflection"],"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"}