Skip to content

Commit e9022da

Browse files
authored
Remove unshaded javax.annotation classes from bootstrap class loader (#4454)
* Fix shading * Revert "Fix shading" This reverts commit 2aad3cf. * Make javax.annotations compileOnly * Replace checker GuardedBy with otel api internal GuardedBy * Fix build * Fix errorprone failures * Remove extra newline * Move internal GuardedBy to instrumentation-api * empty commit * empty commit
1 parent 1b37df7 commit e9022da

File tree

13 files changed

+76
-16
lines changed

13 files changed

+76
-16
lines changed

benchmark-jfr-analyzer/build.gradle.kts

-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@ tasks.withType<JavaCompile>().configureEach {
77
release.set(11)
88
}
99
}
10-
11-
dependencies {
12-
implementation("com.google.code.findbugs:jsr305:3.0.2")
13-
}

conventions/src/main/kotlin/otel.java-conventions.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ dependencies {
9494

9595
components.all<NettyAlignmentRule>()
9696

97-
compileOnly("org.checkerframework:checker-qual")
97+
compileOnly("com.google.code.findbugs:jsr305")
9898

9999
testImplementation("org.junit.jupiter:junit-jupiter-api")
100100
testImplementation("org.junit.jupiter:junit-jupiter-params")

dependencyManagement/build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ val DEPENDENCIES = listOf(
109109
"io.netty:netty:3.10.6.Final",
110110
"org.assertj:assertj-core:3.21.0",
111111
"org.awaitility:awaitility:4.1.0",
112-
"org.checkerframework:checker-qual:3.14.0",
112+
"com.google.code.findbugs:jsr305:3.0.2",
113113
"org.codehaus.groovy:groovy-all:${groovyVersion}",
114114
"org.objenesis:objenesis:3.2",
115115
"org.spockframework:spock-core:1.3-groovy-2.5",

instrumentation-api-annotation-support/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ dependencies {
2020

2121
implementation("io.opentelemetry:opentelemetry-api-metrics")
2222
implementation("org.slf4j:slf4j-api")
23-
implementation("com.google.code.findbugs:jsr305:3.0.2")
2423

2524
compileOnly("com.google.auto.value:auto-value-annotations")
2625
annotationProcessor("com.google.auto.value:auto-value")

instrumentation-api-caching/build.gradle.kts

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ val shadowInclude by configurations.creating {
2020
}
2121

2222
dependencies {
23-
implementation("com.google.code.findbugs:jsr305:3.0.2")
24-
2523
compileOnly(project(":instrumentation-api-caching:caffeine2", configuration = "shadow"))
2624
compileOnly(project(":instrumentation-api-caching:caffeine3", configuration = "shadow"))
2725

26+
compileOnly("org.checkerframework:checker-qual:3.14.0")
2827
compileOnly("com.blogspot.mydailyjava:weak-lock-free")
2928
shadowInclude("com.blogspot.mydailyjava:weak-lock-free")
3029
}

instrumentation-api/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ dependencies {
3030

3131
implementation("io.opentelemetry:opentelemetry-api-metrics")
3232
implementation("org.slf4j:slf4j-api")
33-
implementation("com.google.code.findbugs:jsr305:3.0.2")
3433

3534
compileOnly("com.google.auto.value:auto-value-annotations")
3635
annotationProcessor("com.google.auto.value:auto-value")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.api.internal;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
/**
14+
* The field or method to which this annotation is applied can only be accessed when holding a
15+
* particular lock, which may be a built-in (synchronization) lock, or may be an explicit {@link
16+
* java.util.concurrent.locks.Lock}.
17+
*
18+
* <p>The argument determines which lock guards the annotated field or method:
19+
*
20+
* <ul>
21+
* <li>this : The string literal "this" means that this field is guarded by the class in which it
22+
* is defined.
23+
* <li>class-name.this : For inner classes, it may be necessary to disambiguate 'this'; the
24+
* class-name.this designation allows you to specify which 'this' reference is intended
25+
* <li>itself : For reference fields only; the object to which the field refers.
26+
* <li>field-name : The lock object is referenced by the (instance or static) field specified by
27+
* field-name.
28+
* <li>class-name.field-name : The lock object is reference by the static field specified by
29+
* class-name.field-name.
30+
* <li>method-name() : The lock object is returned by calling the named nil-ary method.
31+
* <li>class-name.class : The Class object for the specified class should be used as the lock
32+
* object.
33+
* </ul>
34+
*
35+
* <p>This annotation is similar to {@link javax.annotation.concurrent.GuardedBy} but has {@link
36+
* RetentionPolicy#SOURCE} so it is not in published artifacts. We only apply this to private
37+
* members, so there is no reason to publish them and we avoid requiring end users to have to depend
38+
* on the annotations in their own build. See the original <a
39+
* href="https://github.com/open-telemetry/opentelemetry-java/issues/2897">issue</a> for more info.
40+
*/
41+
@Target({ElementType.FIELD, ElementType.METHOD})
42+
@Retention(RetentionPolicy.SOURCE)
43+
public @interface GuardedBy {
44+
/** The name of the object guarding the target. */
45+
String value();
46+
}

instrumentation/rxjava/rxjava-2.0/library/src/main/java/io/opentelemetry/instrumentation/rxjava2/TracingAssembly.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.opentelemetry.context.Context;
2626
import io.opentelemetry.context.Scope;
2727
import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndStrategies;
28+
import io.opentelemetry.instrumentation.api.internal.GuardedBy;
2829
import io.reactivex.Completable;
2930
import io.reactivex.CompletableObserver;
3031
import io.reactivex.Flowable;
@@ -40,7 +41,6 @@
4041
import io.reactivex.parallel.ParallelFlowable;
4142
import io.reactivex.plugins.RxJavaPlugins;
4243
import javax.annotation.Nullable;
43-
import org.checkerframework.checker.lock.qual.GuardedBy;
4444
import org.reactivestreams.Subscriber;
4545

4646
/**
@@ -158,6 +158,7 @@ public void disable() {
158158
}
159159
}
160160

161+
@GuardedBy("TracingAssembly.class")
161162
@SuppressWarnings({"rawtypes", "unchecked"})
162163
private static void enableParallel() {
163164
oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
@@ -167,6 +168,7 @@ private static void enableParallel() {
167168
parallelFlowable -> new TracingParallelFlowable(parallelFlowable, Context.current())));
168169
}
169170

171+
@GuardedBy("TracingAssembly.class")
170172
private static void enableCompletable() {
171173
oldOnCompletableSubscribe = RxJavaPlugins.getOnCompletableSubscribe();
172174
RxJavaPlugins.setOnCompletableSubscribe(
@@ -180,6 +182,7 @@ private static void enableCompletable() {
180182
}));
181183
}
182184

185+
@GuardedBy("TracingAssembly.class")
183186
@SuppressWarnings({"rawtypes", "unchecked"})
184187
private static void enableFlowable() {
185188
oldOnFlowableSubscribe = RxJavaPlugins.getOnFlowableSubscribe();
@@ -199,6 +202,7 @@ private static void enableFlowable() {
199202
}));
200203
}
201204

205+
@GuardedBy("TracingAssembly.class")
202206
@SuppressWarnings({"rawtypes", "unchecked"})
203207
private static void enableObservable() {
204208
if (TracingObserver.canEnable()) {
@@ -215,6 +219,7 @@ private static void enableObservable() {
215219
}
216220
}
217221

222+
@GuardedBy("TracingAssembly.class")
218223
@SuppressWarnings({"rawtypes", "unchecked"})
219224
private static void enableSingle() {
220225
oldOnSingleSubscribe = RxJavaPlugins.getOnSingleSubscribe();
@@ -229,6 +234,7 @@ private static void enableSingle() {
229234
}));
230235
}
231236

237+
@GuardedBy("TracingAssembly.class")
232238
@SuppressWarnings({"rawtypes", "unchecked"})
233239
private static void enableMaybe() {
234240
oldOnMaybeSubscribe = RxJavaPlugins.getOnMaybeSubscribe();
@@ -256,31 +262,37 @@ private static void enableWithSpanStrategy(boolean captureExperimentalSpanAttrib
256262
AsyncOperationEndStrategies.instance().registerStrategy(asyncOperationEndStrategy);
257263
}
258264

265+
@GuardedBy("TracingAssembly.class")
259266
private static void disableParallel() {
260267
RxJavaPlugins.setOnParallelAssembly(oldOnParallelAssembly);
261268
oldOnParallelAssembly = null;
262269
}
263270

271+
@GuardedBy("TracingAssembly.class")
264272
private static void disableObservable() {
265273
RxJavaPlugins.setOnObservableSubscribe(oldOnObservableSubscribe);
266274
oldOnObservableSubscribe = null;
267275
}
268276

277+
@GuardedBy("TracingAssembly.class")
269278
private static void disableCompletable() {
270279
RxJavaPlugins.setOnCompletableSubscribe(oldOnCompletableSubscribe);
271280
oldOnCompletableSubscribe = null;
272281
}
273282

283+
@GuardedBy("TracingAssembly.class")
274284
private static void disableFlowable() {
275285
RxJavaPlugins.setOnFlowableSubscribe(oldOnFlowableSubscribe);
276286
oldOnFlowableSubscribe = null;
277287
}
278288

289+
@GuardedBy("TracingAssembly.class")
279290
private static void disableSingle() {
280291
RxJavaPlugins.setOnSingleSubscribe(oldOnSingleSubscribe);
281292
oldOnSingleSubscribe = null;
282293
}
283294

295+
@GuardedBy("TracingAssembly.class")
284296
@SuppressWarnings({"rawtypes", "unchecked"})
285297
private static void disableMaybe() {
286298
RxJavaPlugins.setOnMaybeSubscribe(

instrumentation/rxjava/rxjava-3.0/library/src/main/java/io/opentelemetry/instrumentation/rxjava3/TracingAssembly.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.opentelemetry.context.Context;
2626
import io.opentelemetry.context.Scope;
2727
import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndStrategies;
28+
import io.opentelemetry.instrumentation.api.internal.GuardedBy;
2829
import io.reactivex.rxjava3.core.Completable;
2930
import io.reactivex.rxjava3.core.CompletableObserver;
3031
import io.reactivex.rxjava3.core.Flowable;
@@ -40,7 +41,6 @@
4041
import io.reactivex.rxjava3.parallel.ParallelFlowable;
4142
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
4243
import javax.annotation.Nullable;
43-
import org.checkerframework.checker.lock.qual.GuardedBy;
4444
import org.reactivestreams.Subscriber;
4545

4646
/**
@@ -158,6 +158,7 @@ public void disable() {
158158
}
159159
}
160160

161+
@GuardedBy("TracingAssembly.class")
161162
@SuppressWarnings({"rawtypes", "unchecked"})
162163
private static void enableParallel() {
163164
oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
@@ -167,6 +168,7 @@ private static void enableParallel() {
167168
parallelFlowable -> new TracingParallelFlowable(parallelFlowable, Context.current())));
168169
}
169170

171+
@GuardedBy("TracingAssembly.class")
170172
private static void enableCompletable() {
171173
oldOnCompletableSubscribe = RxJavaPlugins.getOnCompletableSubscribe();
172174
RxJavaPlugins.setOnCompletableSubscribe(
@@ -180,6 +182,7 @@ private static void enableCompletable() {
180182
}));
181183
}
182184

185+
@GuardedBy("TracingAssembly.class")
183186
@SuppressWarnings({"rawtypes", "unchecked"})
184187
private static void enableFlowable() {
185188
oldOnFlowableSubscribe = RxJavaPlugins.getOnFlowableSubscribe();
@@ -199,6 +202,7 @@ private static void enableFlowable() {
199202
}));
200203
}
201204

205+
@GuardedBy("TracingAssembly.class")
202206
@SuppressWarnings({"rawtypes", "unchecked"})
203207
private static void enableObservable() {
204208
oldOnObservableSubscribe = RxJavaPlugins.getOnObservableSubscribe();
@@ -213,6 +217,7 @@ private static void enableObservable() {
213217
}));
214218
}
215219

220+
@GuardedBy("TracingAssembly.class")
216221
@SuppressWarnings({"rawtypes", "unchecked"})
217222
private static void enableSingle() {
218223
oldOnSingleSubscribe = RxJavaPlugins.getOnSingleSubscribe();
@@ -227,6 +232,7 @@ private static void enableSingle() {
227232
}));
228233
}
229234

235+
@GuardedBy("TracingAssembly.class")
230236
@SuppressWarnings({"rawtypes", "unchecked"})
231237
private static void enableMaybe() {
232238
oldOnMaybeSubscribe = RxJavaPlugins.getOnMaybeSubscribe();
@@ -254,31 +260,37 @@ private static void enableWithSpanStrategy(boolean captureExperimentalSpanAttrib
254260
AsyncOperationEndStrategies.instance().registerStrategy(asyncOperationEndStrategy);
255261
}
256262

263+
@GuardedBy("TracingAssembly.class")
257264
private static void disableParallel() {
258265
RxJavaPlugins.setOnParallelAssembly(oldOnParallelAssembly);
259266
oldOnParallelAssembly = null;
260267
}
261268

269+
@GuardedBy("TracingAssembly.class")
262270
private static void disableObservable() {
263271
RxJavaPlugins.setOnObservableSubscribe(oldOnObservableSubscribe);
264272
oldOnObservableSubscribe = null;
265273
}
266274

275+
@GuardedBy("TracingAssembly.class")
267276
private static void disableCompletable() {
268277
RxJavaPlugins.setOnCompletableSubscribe(oldOnCompletableSubscribe);
269278
oldOnCompletableSubscribe = null;
270279
}
271280

281+
@GuardedBy("TracingAssembly.class")
272282
private static void disableFlowable() {
273283
RxJavaPlugins.setOnFlowableSubscribe(oldOnFlowableSubscribe);
274284
oldOnFlowableSubscribe = null;
275285
}
276286

287+
@GuardedBy("TracingAssembly.class")
277288
private static void disableSingle() {
278289
RxJavaPlugins.setOnSingleSubscribe(oldOnSingleSubscribe);
279290
oldOnSingleSubscribe = null;
280291
}
281292

293+
@GuardedBy("TracingAssembly.class")
282294
@SuppressWarnings({"rawtypes", "unchecked"})
283295
private static void disableMaybe() {
284296
RxJavaPlugins.setOnMaybeSubscribe(

javaagent-bootstrap/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ group = "io.opentelemetry.javaagent"
88
dependencies {
99
implementation(project(":instrumentation-api"))
1010
implementation("org.slf4j:slf4j-api")
11-
implementation("com.google.code.findbugs:jsr305:3.0.2")
1211

1312
testImplementation(project(":testing-common"))
1413
testImplementation("org.mockito:mockito-core")

javaagent-extension-api/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ dependencies {
1313
implementation(project(":instrumentation-api"))
1414
implementation(project(":javaagent-instrumentation-api"))
1515
implementation("org.slf4j:slf4j-api")
16-
implementation("com.google.code.findbugs:jsr305:3.0.2")
1716

1817
// metrics are unstable, do not expose as api
1918
implementation("io.opentelemetry:opentelemetry-sdk-metrics")

javaagent-instrumentation-api/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies {
1111
api(project(":instrumentation-api"))
1212

1313
implementation("org.slf4j:slf4j-api")
14-
implementation("com.google.code.findbugs:jsr305:3.0.2")
1514

1615
compileOnly("com.google.auto.value:auto-value-annotations")
1716
annotationProcessor("com.google.auto.value:auto-value")

javaagent-instrumentation-api/src/main/java/io/opentelemetry/javaagent/instrumentation/api/internal/ClassLoaderMatcherCacheHolder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
package io.opentelemetry.javaagent.instrumentation.api.internal;
77

88
import io.opentelemetry.instrumentation.api.caching.Cache;
9+
import io.opentelemetry.instrumentation.api.internal.GuardedBy;
910
import java.net.URL;
1011
import java.util.ArrayList;
1112
import java.util.List;
12-
import org.checkerframework.checker.lock.qual.GuardedBy;
1313

1414
/**
1515
* A holder of all ClassLoaderMatcher caches. We store them in the bootstrap classloader so that

0 commit comments

Comments
 (0)