Skip to content

No ARI events received on Java 25 — Netty reflection failure due to JVM module access restrictions #199

@devanshu-tj

Description

@devanshu-tj

Summary

When using ari4java on Java 25 (or JDK ≥ 22), the ARI WebSocket successfully connects to Asterisk, but no events are ever delivered to the client.
Asterisk logs show that ARI events (e.g., StasisStart) are being emitted, but the client receives nothing.

Root cause traced to Netty failing to initialize due to reflection access restrictions introduced in newer Java versions.


Steps to Reproduce

  1. Use Asterisk 20+ with an ARI app defined in stasis.conf (e.g., astvoice).

  2. Run a Java app that connects via:

    ws://127.0.0.1:8088/ari/events?app=astvoice
  3. Launch using Java 25:

    java -jar voice-bridge.jar
  4. Observe:

    • Asterisk CLI shows:

      <--- Sending ARI event to 127.0.0.1:55964 ---> { "type": "StasisStart", ... }
    • Client shows:

      Received Message - TextWebSocketFrame

      but onStasisStart() or any ARI event handlers are never invoked.


Actual Error Logs

[main] i.n.u.i.PlatformDependent0 - direct buffer constructor: unavailable java.lang.UnsupportedOperationException: Reflective setAccessible(true) disabled at io.netty.util.internal.ReflectionUtil.trySetAccessible(ReflectionUtil.java:31) at io.netty.util.internal.PlatformDependent0$5.run(PlatformDependent0.java:293) at java.base/java.security.AccessController.doPrivileged(AccessController.java:74) at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:286) at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:333) at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:88) at io.netty.channel.nio.NioEventLoop.<clinit>(NioEventLoop.java:84) at io.netty.channel.nio.NioEventLoopGroup.newChild(NioEventLoopGroup.java:182) ... Caused by: java.lang.IllegalAccessException: class io.netty.util.internal.PlatformDependent0$7 cannot access class jdk.internal.misc.Unsafe (in module java.base)

Environment

Component | Version -- | -- Java | 25 (OpenJDK / Oracle) Gradle | 7.3.3 (from repo) Netty | 4.1.66.Final (transitive) Asterisk | 22.6 OS / Platform | Ubuntu 22.04 / Docker

Analysis

  • ari4java’s bundled Netty version relies on reflective access to jdk.internal.misc.Unsafe, which is now blocked in Java 22+ by JEP 403 (Strong Encapsulation of JDK Internals).

  • The reflection fails during Netty’s static initialization (PlatformDependent0.<clinit>), causing its internal NIO event loop to never start properly.

  • Consequently, the WebSocket connection opens, but frames are never processed, so ARI events never reach the registered listener.


Workarounds

1. Use Java 17 or 21
Everything works as expected.

⚙️ 2. Add JVM flag (temporary workaround)

java --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -jar app.jar

Suggested Fix

  • Upgrade dependencies

    dependencies { implementation 'io.netty:netty-all:4.1.112.Final' }

  • Expected Behavior

    ari4java should:

    • Build cleanly on Java 25

    • Initialize Netty without reflection errors

    • Receive and dispatch ARI events (e.g., StasisStart, ChannelStateChange) normally


    Request

    Please update the Gradle wrapper and Netty dependency so ari4java works correctly on modern LTS JVMs (Java 21+) and Java 25.
    This will ensure compatibility with current Docker base images and cloud runtimes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions