-
Notifications
You must be signed in to change notification settings - Fork 66
Description
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
-
Use Asterisk 20+ with an ARI app defined in
stasis.conf(e.g.,astvoice). -
Run a Java app that connects via:
ws://127.0.0.1:8088/ari/events?app=astvoice -
Launch using Java 25:
java -jar voice-bridge.jar -
Observe:
-
Asterisk CLI shows:
<--- Sending ARI event to 127.0.0.1:55964 ---> { "type": "StasisStart", ... } -
Client shows:
Received Message - TextWebSocketFramebut
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
Analysis
-
ari4java’s bundled Netty version relies on reflective access tojdk.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' } -
Build cleanly on Java 25
-
Initialize Netty without reflection errors
-
Receive and dispatch ARI events (e.g.,
StasisStart,ChannelStateChange) normally
Expected Behavior
ari4java should:
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.