Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unshaded javax.annotation classes from bootstrap class loader #4454

Merged
merged 12 commits into from
Oct 21, 2021
4 changes: 0 additions & 4 deletions benchmark-jfr-analyzer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ tasks.withType<JavaCompile>().configureEach {
release.set(11)
}
}

dependencies {
implementation("com.google.code.findbugs:jsr305:3.0.2")
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ dependencies {

components.all<NettyAlignmentRule>()

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

testImplementation("org.junit.jupiter:junit-jupiter-api")
testImplementation("org.junit.jupiter:junit-jupiter-params")
Expand Down
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ val DEPENDENCIES = listOf(
"io.netty:netty:3.10.6.Final",
"org.assertj:assertj-core:3.21.0",
"org.awaitility:awaitility:4.1.0",
"org.checkerframework:checker-qual:3.14.0",
"com.google.code.findbugs:jsr305:3.0.2",
"org.codehaus.groovy:groovy-all:${groovyVersion}",
"org.objenesis:objenesis:3.2",
"org.spockframework:spock-core:1.3-groovy-2.5",
Expand Down
1 change: 0 additions & 1 deletion instrumentation-api-annotation-support/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {

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

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")
Expand Down
3 changes: 1 addition & 2 deletions instrumentation-api-caching/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ val shadowInclude by configurations.creating {
}

dependencies {
implementation("com.google.code.findbugs:jsr305:3.0.2")

compileOnly(project(":instrumentation-api-caching:caffeine2", configuration = "shadow"))
compileOnly(project(":instrumentation-api-caching:caffeine3", configuration = "shadow"))

compileOnly("org.checkerframework:checker-qual:3.14.0")
compileOnly("com.blogspot.mydailyjava:weak-lock-free")
shadowInclude("com.blogspot.mydailyjava:weak-lock-free")
}
Expand Down
1 change: 0 additions & 1 deletion instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ dependencies {

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

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.api.internal;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* The field or method to which this annotation is applied can only be accessed when holding a
* particular lock, which may be a built-in (synchronization) lock, or may be an explicit {@link
* java.util.concurrent.locks.Lock}.
*
* <p>The argument determines which lock guards the annotated field or method:
*
* <ul>
* <li>this : The string literal "this" means that this field is guarded by the class in which it
* is defined.
* <li>class-name.this : For inner classes, it may be necessary to disambiguate 'this'; the
* class-name.this designation allows you to specify which 'this' reference is intended
* <li>itself : For reference fields only; the object to which the field refers.
* <li>field-name : The lock object is referenced by the (instance or static) field specified by
* field-name.
* <li>class-name.field-name : The lock object is reference by the static field specified by
* class-name.field-name.
* <li>method-name() : The lock object is returned by calling the named nil-ary method.
* <li>class-name.class : The Class object for the specified class should be used as the lock
* object.
* </ul>
*
* <p>This annotation is similar to {@link javax.annotation.concurrent.GuardedBy} but has {@link
* RetentionPolicy#SOURCE} so it is not in published artifacts. We only apply this to private
* members, so there is no reason to publish them and we avoid requiring end users to have to depend
* on the annotations in their own build. See the original <a
* href="https://github.com/open-telemetry/opentelemetry-java/issues/2897">issue</a> for more info.
*/
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.SOURCE)
public @interface GuardedBy {
/** The name of the object guarding the target. */
String value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndStrategies;
import io.opentelemetry.instrumentation.api.internal.GuardedBy;
import io.reactivex.Completable;
import io.reactivex.CompletableObserver;
import io.reactivex.Flowable;
Expand All @@ -40,7 +41,6 @@
import io.reactivex.parallel.ParallelFlowable;
import io.reactivex.plugins.RxJavaPlugins;
import javax.annotation.Nullable;
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.reactivestreams.Subscriber;

/**
Expand Down Expand Up @@ -158,6 +158,7 @@ public void disable() {
}
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableParallel() {
oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
Expand All @@ -167,6 +168,7 @@ private static void enableParallel() {
parallelFlowable -> new TracingParallelFlowable(parallelFlowable, Context.current())));
}

@GuardedBy("TracingAssembly.class")
private static void enableCompletable() {
oldOnCompletableSubscribe = RxJavaPlugins.getOnCompletableSubscribe();
RxJavaPlugins.setOnCompletableSubscribe(
Expand All @@ -180,6 +182,7 @@ private static void enableCompletable() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableFlowable() {
oldOnFlowableSubscribe = RxJavaPlugins.getOnFlowableSubscribe();
Expand All @@ -199,6 +202,7 @@ private static void enableFlowable() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableObservable() {
if (TracingObserver.canEnable()) {
Expand All @@ -215,6 +219,7 @@ private static void enableObservable() {
}
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableSingle() {
oldOnSingleSubscribe = RxJavaPlugins.getOnSingleSubscribe();
Expand All @@ -229,6 +234,7 @@ private static void enableSingle() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableMaybe() {
oldOnMaybeSubscribe = RxJavaPlugins.getOnMaybeSubscribe();
Expand Down Expand Up @@ -256,31 +262,37 @@ private static void enableWithSpanStrategy(boolean captureExperimentalSpanAttrib
AsyncOperationEndStrategies.instance().registerStrategy(asyncOperationEndStrategy);
}

@GuardedBy("TracingAssembly.class")
private static void disableParallel() {
RxJavaPlugins.setOnParallelAssembly(oldOnParallelAssembly);
oldOnParallelAssembly = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableObservable() {
RxJavaPlugins.setOnObservableSubscribe(oldOnObservableSubscribe);
oldOnObservableSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableCompletable() {
RxJavaPlugins.setOnCompletableSubscribe(oldOnCompletableSubscribe);
oldOnCompletableSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableFlowable() {
RxJavaPlugins.setOnFlowableSubscribe(oldOnFlowableSubscribe);
oldOnFlowableSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableSingle() {
RxJavaPlugins.setOnSingleSubscribe(oldOnSingleSubscribe);
oldOnSingleSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void disableMaybe() {
RxJavaPlugins.setOnMaybeSubscribe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.annotation.support.async.AsyncOperationEndStrategies;
import io.opentelemetry.instrumentation.api.internal.GuardedBy;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.CompletableObserver;
import io.reactivex.rxjava3.core.Flowable;
Expand All @@ -40,7 +41,6 @@
import io.reactivex.rxjava3.parallel.ParallelFlowable;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import javax.annotation.Nullable;
import org.checkerframework.checker.lock.qual.GuardedBy;
import org.reactivestreams.Subscriber;

/**
Expand Down Expand Up @@ -158,6 +158,7 @@ public void disable() {
}
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableParallel() {
oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
Expand All @@ -167,6 +168,7 @@ private static void enableParallel() {
parallelFlowable -> new TracingParallelFlowable(parallelFlowable, Context.current())));
}

@GuardedBy("TracingAssembly.class")
private static void enableCompletable() {
oldOnCompletableSubscribe = RxJavaPlugins.getOnCompletableSubscribe();
RxJavaPlugins.setOnCompletableSubscribe(
Expand All @@ -180,6 +182,7 @@ private static void enableCompletable() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableFlowable() {
oldOnFlowableSubscribe = RxJavaPlugins.getOnFlowableSubscribe();
Expand All @@ -199,6 +202,7 @@ private static void enableFlowable() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableObservable() {
oldOnObservableSubscribe = RxJavaPlugins.getOnObservableSubscribe();
Expand All @@ -213,6 +217,7 @@ private static void enableObservable() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableSingle() {
oldOnSingleSubscribe = RxJavaPlugins.getOnSingleSubscribe();
Expand All @@ -227,6 +232,7 @@ private static void enableSingle() {
}));
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableMaybe() {
oldOnMaybeSubscribe = RxJavaPlugins.getOnMaybeSubscribe();
Expand Down Expand Up @@ -254,31 +260,37 @@ private static void enableWithSpanStrategy(boolean captureExperimentalSpanAttrib
AsyncOperationEndStrategies.instance().registerStrategy(asyncOperationEndStrategy);
}

@GuardedBy("TracingAssembly.class")
private static void disableParallel() {
RxJavaPlugins.setOnParallelAssembly(oldOnParallelAssembly);
oldOnParallelAssembly = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableObservable() {
RxJavaPlugins.setOnObservableSubscribe(oldOnObservableSubscribe);
oldOnObservableSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableCompletable() {
RxJavaPlugins.setOnCompletableSubscribe(oldOnCompletableSubscribe);
oldOnCompletableSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableFlowable() {
RxJavaPlugins.setOnFlowableSubscribe(oldOnFlowableSubscribe);
oldOnFlowableSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
private static void disableSingle() {
RxJavaPlugins.setOnSingleSubscribe(oldOnSingleSubscribe);
oldOnSingleSubscribe = null;
}

@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void disableMaybe() {
RxJavaPlugins.setOnMaybeSubscribe(
Expand Down
1 change: 0 additions & 1 deletion javaagent-bootstrap/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ group = "io.opentelemetry.javaagent"
dependencies {
implementation(project(":instrumentation-api"))
implementation("org.slf4j:slf4j-api")
implementation("com.google.code.findbugs:jsr305:3.0.2")

testImplementation(project(":testing-common"))
testImplementation("org.mockito:mockito-core")
Expand Down
1 change: 0 additions & 1 deletion javaagent-extension-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ dependencies {
implementation(project(":instrumentation-api"))
implementation(project(":javaagent-instrumentation-api"))
implementation("org.slf4j:slf4j-api")
implementation("com.google.code.findbugs:jsr305:3.0.2")

// metrics are unstable, do not expose as api
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
Expand Down
1 change: 0 additions & 1 deletion javaagent-instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
api(project(":instrumentation-api"))

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

compileOnly("com.google.auto.value:auto-value-annotations")
annotationProcessor("com.google.auto.value:auto-value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package io.opentelemetry.javaagent.instrumentation.api.internal;

import io.opentelemetry.instrumentation.api.caching.Cache;
import io.opentelemetry.instrumentation.api.internal.GuardedBy;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.lock.qual.GuardedBy;

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