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

* Fix shading

* Revert "Fix shading"

This reverts commit 2aad3cfe21.

* 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
This commit is contained in:
Trask Stalnaker 2021-10-21 14:47:50 -07:00 committed by GitHub
parent 1b37df7afd
commit e9022da102
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 76 additions and 16 deletions

View File

@ -7,7 +7,3 @@ tasks.withType<JavaCompile>().configureEach {
release.set(11)
}
}
dependencies {
implementation("com.google.code.findbugs:jsr305:3.0.2")
}

View File

@ -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")

View File

@ -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",

View File

@ -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")

View File

@ -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")
}

View File

@ -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")

View File

@ -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();
}

View File

@ -25,6 +25,7 @@ package io.opentelemetry.instrumentation.rxjava2;
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;
@ -40,7 +41,6 @@ import io.reactivex.internal.fuseable.ConditionalSubscriber;
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;
/**
@ -158,6 +158,7 @@ public final class TracingAssembly {
}
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableParallel() {
oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
@ -167,6 +168,7 @@ public final class TracingAssembly {
parallelFlowable -> new TracingParallelFlowable(parallelFlowable, Context.current())));
}
@GuardedBy("TracingAssembly.class")
private static void enableCompletable() {
oldOnCompletableSubscribe = RxJavaPlugins.getOnCompletableSubscribe();
RxJavaPlugins.setOnCompletableSubscribe(
@ -180,6 +182,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableFlowable() {
oldOnFlowableSubscribe = RxJavaPlugins.getOnFlowableSubscribe();
@ -199,6 +202,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableObservable() {
if (TracingObserver.canEnable()) {
@ -215,6 +219,7 @@ public final class TracingAssembly {
}
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableSingle() {
oldOnSingleSubscribe = RxJavaPlugins.getOnSingleSubscribe();
@ -229,6 +234,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableMaybe() {
oldOnMaybeSubscribe = RxJavaPlugins.getOnMaybeSubscribe();
@ -256,31 +262,37 @@ public final class TracingAssembly {
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(

View File

@ -25,6 +25,7 @@ package io.opentelemetry.instrumentation.rxjava3;
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;
@ -40,7 +41,6 @@ import io.reactivex.rxjava3.internal.fuseable.ConditionalSubscriber;
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;
/**
@ -158,6 +158,7 @@ public final class TracingAssembly {
}
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableParallel() {
oldOnParallelAssembly = RxJavaPlugins.getOnParallelAssembly();
@ -167,6 +168,7 @@ public final class TracingAssembly {
parallelFlowable -> new TracingParallelFlowable(parallelFlowable, Context.current())));
}
@GuardedBy("TracingAssembly.class")
private static void enableCompletable() {
oldOnCompletableSubscribe = RxJavaPlugins.getOnCompletableSubscribe();
RxJavaPlugins.setOnCompletableSubscribe(
@ -180,6 +182,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableFlowable() {
oldOnFlowableSubscribe = RxJavaPlugins.getOnFlowableSubscribe();
@ -199,6 +202,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableObservable() {
oldOnObservableSubscribe = RxJavaPlugins.getOnObservableSubscribe();
@ -213,6 +217,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableSingle() {
oldOnSingleSubscribe = RxJavaPlugins.getOnSingleSubscribe();
@ -227,6 +232,7 @@ public final class TracingAssembly {
}));
}
@GuardedBy("TracingAssembly.class")
@SuppressWarnings({"rawtypes", "unchecked"})
private static void enableMaybe() {
oldOnMaybeSubscribe = RxJavaPlugins.getOnMaybeSubscribe();
@ -254,31 +260,37 @@ public final class TracingAssembly {
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(

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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