Skip to content

Commit 69c5529

Browse files
committed
Move FlagEvalHook construction inside try/catch block
FlagEvalHook references FlagEvalMetrics in its field declaration. On JVMs that eagerly verify field types during class loading, constructing FlagEvalHook outside the try/catch could throw NoClassDefFoundError if OTel classes failed to load. Moving it inside the try block ensures both metrics and hook are null-safe when OTel is absent.
1 parent 3d789f0 commit 69c5529

File tree

1 file changed

+3
-1
lines changed
  • products/feature-flagging/feature-flagging-api/src/main/java/datadog/trace/api/openfeature

1 file changed

+3
-1
lines changed

products/feature-flagging/feature-flagging-api/src/main/java/datadog/trace/api/openfeature/Provider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ public Provider(final Options options) {
4343
this.options = options;
4444
this.evaluator = evaluator;
4545
FlagEvalMetrics metrics = null;
46+
FlagEvalHook hook = null;
4647
try {
4748
metrics = new FlagEvalMetrics();
49+
hook = new FlagEvalHook(metrics);
4850
} catch (NoClassDefFoundError | Exception e) {
4951
// OTel classes not on classpath — metrics disabled
5052
}
5153
this.flagEvalMetrics = metrics;
52-
this.flagEvalHook = new FlagEvalHook(metrics);
54+
this.flagEvalHook = hook;
5355
}
5456

5557
@Override

0 commit comments

Comments
 (0)