apache/druid · error · UnsupportedOperationException

sun.misc.Unsafe is not supported on this platform, because…

Error message

sun.misc.Unsafe is not supported on this platform, because internal Java APIs are not compatible with this Druid version

What it means

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.

Solutions

  1. 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
  2. Check the chained cause (UNSAFE_NOT_SUPPORTED_EXCEPTION) logged at startup to see why Unsafe acquisition failed and fix that root cause
  3. Upgrade Druid to a release that no longer requires sun.misc.Unsafe on your JDK version
  4. If Unsafe is genuinely unavailable in your environment, avoid code paths that call UnsafeUtils.theUnsafe() or vendor a patched UnsafeUtils

Example fix

// before (JDK 17 startup)
java -jar druid.jar
// after
java --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
Defensive patterns

Strategy: try-catch

Validate before calling

// Check JVM compatibility before relying on Unsafe-dependent paths
boolean unsafeUsable = "HotSpot".equalsIgnoreCase(System.getProperty("java.vm.name").replaceAll(".*HotSpot.*", "HotSpot"))
    && !System.getProperty("java.specification.version").matches("(1[7-9]|[2-9][0-9]).*") ; // adjust to Druid's supported range

Try / catch

try {
  Object unsafe = UnsafeUtils.theUnsafe();
  // use unsafe
} catch (UnsupportedOperationException e) {
  // fall back to non-Unsafe implementation or fail fast with guidance
  log.warn(e, "sun.misc.Unsafe unavailable; falling back");
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/1bed6ea38ca42ba5. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/java/util/common/UnsafeUtils.java:67

    }

    if (theUnsafe != null) {
      UNSAFE = theUnsafe;
      UNSAFE_CLASS = unsafeClass;
      UNSAFE_NOT_SUPPORTED_EXCEPTION = exception;
    } else {
      UNSAFE_CLASS = null;
      UNSAFE = null;
      UNSAFE_NOT_SUPPORTED_EXCEPTION = exception;
    }
  }

  public static Object theUnsafe()
  {
    if (UNSAFE != null) {
      return UNSAFE;
    } else {
      throw new UnsupportedOperationException(MESSAGE, UNSAFE_NOT_SUPPORTED_EXCEPTION);
    }
  }

  public static Class<?> theUnsafeClass()
  {
    if (UNSAFE_CLASS != null) {
      return UNSAFE_CLASS;
    } else {
      throw new UnsupportedOperationException(MESSAGE, UNSAFE_NOT_SUPPORTED_EXCEPTION);
    }
  }
}

View on GitHub (pinned to 9b90983fd2)