Skip to content

Java 25 support: drop the deprecated sun.misc.Unsafe path (jctools atomic queue)#802

Open
vasiliy-mikhailov wants to merge 1 commit into
hivemq:masterfrom
vasiliy-mikhailov:java25-jctools-unsafe
Open

Java 25 support: drop the deprecated sun.misc.Unsafe path (jctools atomic queue)#802
vasiliy-mikhailov wants to merge 1 commit into
hivemq:masterfrom
vasiliy-mikhailov:java25-jctools-unsafe

Conversation

@vasiliy-mikhailov

Copy link
Copy Markdown

Java 25 support: drop the deprecated sun.misc.Unsafe path

Resolves #775.

A plain jctools version bump does not fix it

The issue proposes bumping jctools to silence the terminally-deprecated
sun.misc.Unsafe warning on Java 25. I checked that directly, exercising the exact
queue this project uses (SpscUnboundedArrayQueue) on Temurin 25.0.3:

jctools warning on Java 25
2.1.2 (current) sun.misc.Unsafe::objectFieldOffset ⚠️
4.0.5 still sun.misc.Unsafe::objectFieldOffset ⚠️
4.0.5, atomic queue clean

jctools is built on Unsafe by design, so a newer version still trips the
warning.

The fix

jctools ships Unsafe-free *Atomic* queue variants (backed by
AtomicReferenceFieldUpdater) for exactly this situation. The only jctools usage
in the project is a single SPSC queue in MqttOutgoingQosHandler, so switching it
to org.jctools.queues.atomic.SpscUnboundedAtomicArrayQueue removes the Unsafe
code path entirely while keeping identical queue semantics:

-import org.jctools.queues.SpscUnboundedArrayQueue;
+import org.jctools.queues.atomic.SpscUnboundedAtomicArrayQueue;
...
-private final @NotNull SpscUnboundedArrayQueue<MqttPublishWithFlow> queue = new SpscUnboundedArrayQueue<>(32);
+private final @NotNull SpscUnboundedAtomicArrayQueue<MqttPublishWithFlow> queue = new SpscUnboundedAtomicArrayQueue<>(32);

The atomic variant uses field updaters rather than raw Unsafe offsets — a
negligible difference for this per-connection outgoing queue, and the idiomatic
jctools choice when Unsafe is unavailable or undesired. jctools is also bumped
2.1.2 → 4.0.5, as the issue requested.

Verification

  • On Temurin 25.0.3, the atomic queue emits no sun.misc.Unsafe
    deprecation warning (the Unsafe-based queue does).
  • Full ./gradlew test: 2619 passing / 12 skipped / 0 failures, identical
    before and after.
  • ./gradlew assemble builds the shaded jar with the relocated atomic class.

Note: the build uses Gradle 8.14.3, which cannot itself run a Java 25 toolchain
(./gradlew test on JDK 25 fails to parse the version string). That's a separate,
build-only concern (needs Gradle ≥ 9); this PR addresses the library's runtime
Unsafe usage when consumed on Java 25.

🤖 Generated with Claude Code

The outgoing-QoS queue used org.jctools.queues.SpscUnboundedArrayQueue, which
reaches sun.misc.Unsafe and triggers a terminal-deprecation warning on Java 25.
A jctools version bump alone does not fix this: 4.0.5 still calls deprecated
Unsafe (verified on Temurin 25.0.3). Switching the single usage to the
Unsafe-free org.jctools.queues.atomic.SpscUnboundedAtomicArrayQueue (backed by
AtomicReferenceFieldUpdater) removes the Unsafe code path with identical SPSC
queue semantics. Also bumps jctools 2.1.2 -> 4.0.5 as the issue requested.

Full test suite unchanged: 2619 passing / 12 skipped / 0 failures.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cla-bot

cla-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have the users @vasiliy-mikhailov on file. In order for us to review and merge your code, please sign our Contributor License Agreement to get yourself added. You'll find the CLA and more information here: https://github.com/hivemq/hivemq-community/blob/master/CONTRIBUTING.adoc#contributor-license-agreement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Java 25 support - JCTools Version Bump needed

1 participant