UnsupportedOperationException at startup when using JDK 26+
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
co.elastic.apm.agent.bci.IndyBootstrap#loadClassInBootstrap から始め、Byte Buddy の ClassInjector をどのように呼び出しているかを調査します。その経路を、参照されている OpenTelemetry の HelperInjector 実装と比較し、その後 JDK 26 以降でエージェントの起動を再現します。報告されている UnsupportedOperationException で起動が失敗しなくなり、一時的な system-property による workaround に依存しなくなれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Initially reported in our forum.
2026-06-25 17:22:20,878 [main] ERROR co.elastic.apm.agent.bci.ElasticApmAgent - Exception occurred while applying instrumentation co.elastic.apm.agent.java_ldap.LdapClientInstrumentation
java.lang.RuntimeException: java.lang.UnsupportedOperationException: Could not access Unsafe class: As of Java 26, using Unsafe is disabled by default, set net.bytebuddy.safe to true if you want to use the JVM's internal unsafe API even though it will become unsupported in the future and should be replaced by injection using method handles: net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup
at co.elastic.apm.agent.bci.IndyBootstrap.getIndyBootstrapMethod(IndyBootstrap.java:240) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.ElasticApmAgent.getTransformer(ElasticApmAgent.java:486) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.ElasticApmAgent.applyAdvice(ElasticApmAgent.java:444) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.ElasticApmAgent.initAgentBuilder(ElasticApmAgent.java:365) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.ElasticApmAgent.initInstrumentation(ElasticApmAgent.java:290) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.ElasticApmAgent.initInstrumentation(ElasticApmAgent.java:179) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.ElasticApmAgent.initialize(ElasticApmAgent.java:165) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:565) ~[?:?]
at co.elastic.apm.agent.premain.AgentMain.loadAndInitializeAgent(AgentMain.java:157) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.premain.AgentMain.init(AgentMain.java:98) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.premain.AgentMain.premain(AgentMain.java:47) [elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:565) ~[?:?]
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:544) [?:?]
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:556) [?:?]
Caused by: java.lang.UnsupportedOperationException: Could not access Unsafe class: As of Java 26, using Unsafe is disabled by default, set net.bytebuddy.safe to true if you want to use the JVM's internal unsafe API even though it will become unsupported in the future and should be replaced by injection using method handles: net.bytebuddy.dynamic.loading.ClassInjector$UsingLookup
at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe$Dispatcher$Unavailable.initialize(ClassInjector.java:2206) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at net.bytebuddy.dynamic.loading.ClassInjector$UsingUnsafe.injectRaw(ClassInjector.java:1907) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at net.bytebuddy.dynamic.loading.ClassInjector$AbstractBase.injectRaw(ClassInjector.java:202) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.IndyBootstrap.loadClassInBootstrap(IndyBootstrap.java:310) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.IndyBootstrap.initIndyBootstrap(IndyBootstrap.java:268) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
at co.elastic.apm.agent.bci.IndyBootstrap.getIndyBootstrapMethod(IndyBootstrap.java:234) ~[elastic-apm-agent-1.56.1-SNAPSHOT.jar:1.56.1-SNAPSHOT]
... 15 more
I think we need to modify the call to ClassInjector inco.elastic.apm.agent.bci.IndyBootstrap#loadClassInBootstrap method to implement something close to what is being done in upstream otel in https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/31188f0f8190356f8b943c81a0c8c51e9a45e6c4/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/HelperInjector.java#L391
As reference, here is the PR that mainly contributed to the current version (where Unsafe usages were being removed) : https://github.com/open-telemetry/opentelemetry-java-instrumentation/pull/14855
The temporary workaround is to set net.bytebuddy.safe = false in Java system properties by adding the -Dnet.bytebuddy.safe=false JVM command line argument.
- 主要言語
- Java
- スター
- 593
- フォーク
- 337
- 平均マージ
- 15時間 24分
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
elastic/apm-agent-java のほかの issue
-
agent-java
難易度 2/5 1〜2日 初心者へのやさしさ 62/100
elastic/apm-agent-java#2844 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Improve docs and add error log related to illegal activation of transaction対応中かも @AzazelSensei が 30 日前に担当しました。 オープンdocs good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
elastic/apm-agent-java#850 · コメント 4 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Custom HttpURLConnection throwing unchecked exception can stall the agent対応中かも @jackshirazi が 1 日前に担当しました。 オープンagent-java bug
elastic/apm-agent-java#4590 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
agent-java community triage
elastic/apm-agent-java#4573 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
agent-java
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
elastic/apm-agent-java#4549 ·
メンテナーはふだん 1 日以内に返信
elastic/apm-agent-java の issue をすべて見る
似ている issue
-
backend
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bcgov/nr-forest-client#2524 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
Sinytra/ForgifiedFabricAPI#298 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
team:Lumberjack
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
OpenLiberty/open-liberty#35998 ·
メンテナーはふだん 1 日以内に返信