binance / binance/binance-connector-java
`NoSuchElementException` from `ServiceLoader` in Async Context
- Dominant language
- Java
- Stars
- 581
- Forks
- 255
- Avg merge
- 2m
- Merged PRs (30d)
- 2
Description
This report details a critical runtime exception encountered for derivatives trading (USDS Futures) within a Play Framework 3 / Pekko environment.
When initializing the WebSocket client within a `CompletableFuture` (e.g., on Play's default `ForkJoinPool`), the `ServiceLoader` mechanism fails to find Jetty WebSocket extension implementations.
- **Error:** `java.util.NoSuchElementException` originating from `java.util.ServiceLoader` and traced up through `org.eclipse.jetty.websocket.api.ExtensionConfig.getParser`.
- **Cause:** The `ServiceLoader` relies on the `Thread.currentThread().getContextClassLoader()`. When the initialization code runs on a worker thread from a thread pool (like `ForkJoinPool`), this context classloader may not have visibility of the full application dependency classpath where the Jetty service implementations reside.
- **Trigger:** Instantiating `new DerivativesTradingUsdsFuturesWebSocketStreams(wsConnectionPool)` inside a `CompletableFuture.supplyAsync()` block.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.