Fix some java lint warnings (#5120)

* Convert InstrumentationTestRunner from interface to abstract class

* Foo

* Commit

* Revert unintended
This commit is contained in:
Anuraag Agrawal 2022-01-18 03:26:03 +09:00 committed by GitHub
parent eea7c0f1dc
commit b7a95857c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 189 additions and 100 deletions

View File

@ -40,6 +40,10 @@ tasks {
disable("StringSplitter")
disable("ImmutableMemberCollection")
// Fully qualified names may be necessary when deprecating a class to avoid
// deprecation warning.
disable("UnnecessarilyFullyQualified")
// Don't currently use this (to indicate a local variable that's mutated) but could
// consider for future.
disable("Var")

View File

@ -102,6 +102,7 @@ val DEPENDENCIES = listOf(
"io.opentelemetry.proto:opentelemetry-proto:0.11.0-alpha",
"org.assertj:assertj-core:3.22.0",
"org.awaitility:awaitility:4.1.1",
"com.google.code.findbugs:annotations:3.0.1u2",
"com.google.code.findbugs:jsr305:3.0.2",
"org.codehaus.groovy:groovy-all:${groovyVersion}",
"org.objenesis:objenesis:3.2",

View File

@ -46,6 +46,13 @@ tasks {
exclude("**/concurrentlinkedhashmap/**")
}
// Work around https://github.com/jflex-de/jflex/issues/762
compileJava {
with(options) {
compilerArgs.add("-Xlint:-fallthrough")
}
}
sourcesJar {
dependsOn("generateJflex")
}

View File

@ -211,7 +211,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
transient Set<Entry<K, V>> entrySet;
/** Creates an instance based on the builder's configuration. */
@SuppressWarnings({"unchecked", "cast"})
@SuppressWarnings({"unchecked", "cast", "rawtypes"})
private ConcurrentLinkedHashMap(Builder<K, V> builder) {
// The data store and its maximum capacity
concurrencyLevel = builder.concurrencyLevel;
@ -1110,7 +1110,7 @@ public final class ConcurrentLinkedHashMap<K, V> extends AbstractMap<K, V>
*/
@SuppressWarnings("serial")
static final class Node<K, V> extends AtomicReference<WeightedValue<V>>
implements Linked<Node<K, V>> {
implements LinkedDeque.Linked<Node<K, V>> {
final K key;
@GuardedBy("evictionLock")

View File

@ -50,7 +50,8 @@ import javax.annotation.concurrent.NotThreadSafe;
* http://code.google.com/p/concurrentlinkedhashmap/</a>
*/
@NotThreadSafe
final class LinkedDeque<E extends Linked<E>> extends AbstractCollection<E> implements Deque<E> {
final class LinkedDeque<E extends LinkedDeque.Linked<E>> extends AbstractCollection<E>
implements Deque<E> {
// This class provides a doubly-linked list that is optimized for the virtual
// machine. The first and last elements are manipulated instead of a slightly
@ -424,26 +425,26 @@ final class LinkedDeque<E extends Linked<E>> extends AbstractCollection<E> imple
/** Retrieves the next element to traverse to or <tt>null</tt> if there are no more elements. */
abstract E computeNext();
}
}
/** An element that is linked on the {@link Deque}. */
interface Linked<T extends Linked<T>> {
/**
* Retrieves the previous element or <tt>null</tt> if either the element is unlinked or the first
* element on the deque.
*/
T getPrevious();
/** Sets the previous element or <tt>null</tt> if there is no link. */
void setPrevious(T prev);
/**
* Retrieves the next element or <tt>null</tt> if either the element is unlinked or the last
* element on the deque.
*/
T getNext();
/** Sets the next element or <tt>null</tt> if there is no link. */
void setNext(T next);
/** An element that is linked on the {@link Deque}. */
interface Linked<T extends Linked<T>> {
/**
* Retrieves the previous element or <tt>null</tt> if either the element is unlinked or the
* first element on the deque.
*/
T getPrevious();
/** Sets the previous element or <tt>null</tt> if there is no link. */
void setPrevious(T prev);
/**
* Retrieves the next element or <tt>null</tt> if either the element is unlinked or the last
* element on the deque.
*/
T getNext();
/** Sets the next element or <tt>null</tt> if there is no link. */
void setNext(T next);
}
}

View File

@ -6,6 +6,8 @@
package io.opentelemetry.instrumentation.api.config;
public class ConfigParsingException extends RuntimeException {
private static final long serialVersionUID = 1L;
public ConfigParsingException(String message) {
super(message);
}

View File

@ -98,7 +98,9 @@ public final class InstrumenterBuilder<REQUEST, RESPONSE> {
}
/** Adds {@link AttributesExtractor}s to extract attributes from requests and responses. */
public InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractors(
@SafeVarargs
@SuppressWarnings("varargs")
public final InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractors(
AttributesExtractor<? super REQUEST, ? super RESPONSE>... attributesExtractors) {
return addAttributesExtractors(Arrays.asList(attributesExtractors));
}

View File

@ -21,6 +21,8 @@ import java.util.Map;
final class UnsafeAttributes extends HashMap<AttributeKey<?>, Object>
implements Attributes, AttributesBuilder {
private static final long serialVersionUID = 1L;
// Attributes
@SuppressWarnings("unchecked")

View File

@ -43,6 +43,7 @@ public final class RuntimeVirtualFieldSupplier {
ownerToFieldToImplementationMap = Cache.weak();
@Override
@SuppressWarnings("unchecked")
public <U extends T, T, F> VirtualField<U, F> find(Class<T> type, Class<F> fieldType) {
return (VirtualField<U, F>)
ownerToFieldToImplementationMap

View File

@ -10,7 +10,6 @@ import static io.opentelemetry.api.trace.SpanKind.CLIENT;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress;
import javax.annotation.Nullable;
@ -30,13 +29,17 @@ public abstract class DatabaseClientTracer<CONNECTION, STATEMENT, SANITIZEDSTATE
extends BaseTracer {
private static final String DB_QUERY = "DB Query";
protected final NetPeerAttributes netPeerAttributes;
protected final io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes
netPeerAttributes;
protected DatabaseClientTracer(NetPeerAttributes netPeerAttributes) {
protected DatabaseClientTracer(
io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) {
this.netPeerAttributes = netPeerAttributes;
}
protected DatabaseClientTracer(OpenTelemetry openTelemetry, NetPeerAttributes netPeerAttributes) {
protected DatabaseClientTracer(
OpenTelemetry openTelemetry,
io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) {
super(openTelemetry);
this.netPeerAttributes = netPeerAttributes;
}

View File

@ -16,7 +16,6 @@ import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.api.instrumenter.http.HttpStatusConverter;
import io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.URI;
import java.net.URISyntaxException;
@ -41,14 +40,18 @@ public abstract class HttpClientTracer<REQUEST, CARRIER, RESPONSE> extends BaseT
protected static final String USER_AGENT = "User-Agent";
protected final NetPeerAttributes netPeerAttributes;
protected final io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes
netPeerAttributes;
protected HttpClientTracer(NetPeerAttributes netPeerAttributes) {
protected HttpClientTracer(
io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) {
super();
this.netPeerAttributes = netPeerAttributes;
}
protected HttpClientTracer(OpenTelemetry openTelemetry, NetPeerAttributes netPeerAttributes) {
protected HttpClientTracer(
OpenTelemetry openTelemetry,
io.opentelemetry.instrumentation.api.tracer.net.NetPeerAttributes netPeerAttributes) {
super(openTelemetry);
this.netPeerAttributes = netPeerAttributes;
}

View File

@ -10,7 +10,6 @@ import static java.util.Collections.emptyMap;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.instrumentation.api.tracer.AttributeSetter;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -49,7 +48,9 @@ public final class NetPeerAttributes {
setNetPeer(span::setAttribute, remoteConnection);
}
public void setNetPeer(AttributeSetter span, @Nullable InetSocketAddress remoteConnection) {
public void setNetPeer(
io.opentelemetry.instrumentation.api.tracer.AttributeSetter span,
@Nullable InetSocketAddress remoteConnection) {
if (remoteConnection != null) {
InetAddress remoteAddress = remoteConnection.getAddress();
if (remoteAddress != null) {
@ -79,7 +80,10 @@ public final class NetPeerAttributes {
}
public void setNetPeer(
AttributeSetter span, @Nullable String peerName, @Nullable String peerIp, int port) {
io.opentelemetry.instrumentation.api.tracer.AttributeSetter span,
@Nullable String peerName,
@Nullable String peerIp,
int port) {
if (peerName != null && !peerName.equals(peerIp)) {
span.setAttribute(SemanticAttributes.NET_PEER_NAME, peerName);
}

View File

@ -12,11 +12,11 @@ import java.util.function.BiFunction;
final class LambdaParameters {
static <T> Object[] toArray(
Method targetMethod, T input, Context context, BiFunction<T, Class, Object> mapper) {
Method targetMethod, T input, Context context, BiFunction<T, Class<?>, Object> mapper) {
Class<?>[] parameterTypes = targetMethod.getParameterTypes();
Object[] parameters = new Object[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
Class clazz = parameterTypes[i];
Class<?> clazz = parameterTypes[i];
boolean isContext = clazz.equals(Context.class);
if (isContext) {
parameters[i] = context;

View File

@ -27,12 +27,12 @@ public class TracingRequestApiGatewayWrapper
TracingRequestApiGatewayWrapper(
OpenTelemetrySdk openTelemetrySdk,
WrappedLambda wrappedLambda,
BiFunction<APIGatewayProxyRequestEvent, Class, Object> mapper) {
BiFunction<APIGatewayProxyRequestEvent, Class<?>, Object> mapper) {
super(openTelemetrySdk, wrappedLambda, mapper);
}
// Visible for testing
static Object map(APIGatewayProxyRequestEvent event, Class clazz) {
static <T> T map(APIGatewayProxyRequestEvent event, Class<T> clazz) {
try {
return OBJECT_MAPPER.readValue(event.getBody(), clazz);
} catch (JsonProcessingException e) {
@ -45,7 +45,7 @@ public class TracingRequestApiGatewayWrapper
protected APIGatewayProxyResponseEvent doHandleRequest(
APIGatewayProxyRequestEvent input, Context context) {
Object result = super.doHandleRequest(input, context);
APIGatewayProxyResponseEvent event = null;
APIGatewayProxyResponseEvent event;
// map to response event if needed
if (result instanceof APIGatewayProxyResponseEvent) {
event = (APIGatewayProxyResponseEvent) result;

View File

@ -21,12 +21,12 @@ public class TracingRequestWrapper extends TracingRequestWrapperBase<Object, Obj
TracingRequestWrapper(
OpenTelemetrySdk openTelemetrySdk,
WrappedLambda wrappedLambda,
BiFunction<Object, Class, Object> mapper) {
BiFunction<Object, Class<?>, Object> mapper) {
super(openTelemetrySdk, wrappedLambda, mapper);
}
// Visible for testing
static Object map(Object jsonMap, Class clazz) {
static <T> T map(Object jsonMap, Class<T> clazz) {
try {
return OBJECT_MAPPER.convertValue(jsonMap, clazz);
} catch (IllegalArgumentException e) {

View File

@ -26,9 +26,9 @@ abstract class TracingRequestWrapperBase<I, O> extends TracingRequestHandler<I,
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
private final WrappedLambda wrappedLambda;
private final Method targetMethod;
private final BiFunction<I, Class, Object> parameterMapper;
private final BiFunction<I, Class<?>, Object> parameterMapper;
protected TracingRequestWrapperBase(BiFunction<I, Class, Object> parameterMapper) {
protected TracingRequestWrapperBase(BiFunction<I, Class<?>, Object> parameterMapper) {
this(
AutoConfiguredOpenTelemetrySdk.initialize().getOpenTelemetrySdk(),
WrappedLambda.fromConfiguration(),
@ -39,7 +39,7 @@ abstract class TracingRequestWrapperBase<I, O> extends TracingRequestHandler<I,
TracingRequestWrapperBase(
OpenTelemetrySdk openTelemetrySdk,
WrappedLambda wrappedLambda,
BiFunction<I, Class, Object> parameterMapper) {
BiFunction<I, Class<?>, Object> parameterMapper) {
super(openTelemetrySdk, WrapperConfiguration.flushTimeout());
this.wrappedLambda = wrappedLambda;
this.targetMethod = wrappedLambda.getRequestTargetMethod();
@ -47,6 +47,7 @@ abstract class TracingRequestWrapperBase<I, O> extends TracingRequestHandler<I,
}
@Override
@SuppressWarnings("unchecked")
protected O doHandleRequest(I input, Context context) {
Object[] parameters = LambdaParameters.toArray(targetMethod, input, context, parameterMapper);
O result;

View File

@ -27,7 +27,10 @@ final class HeadersFactory {
String name = jParser.getCurrentName();
if ("headers".equalsIgnoreCase(name)) {
jParser.nextToken();
return OBJECT_MAPPER.readValue(jParser, Map.class);
@SuppressWarnings("unchecked")
Map<String, String> map =
(Map<String, String>) OBJECT_MAPPER.readValue(jParser, Map.class);
return map;
}
}
} catch (Exception e) {

View File

@ -40,8 +40,10 @@ final class AwsJsonProtocolFactoryAccess {
// AwsJsonProtocolFactory requires any URI to be present
.option(SdkClientOption.ENDPOINT, URI.create("http://empty"))
.build());
@SuppressWarnings("rawtypes")
Class awsJsonProtocolClass =
Class.forName("software.amazon.awssdk.protocols.json.AwsJsonProtocol");
@SuppressWarnings("unchecked")
Object awsJsonProtocol = Enum.valueOf(awsJsonProtocolClass, "AWS_JSON");
awsJsonProtocolFactoryBuilder
.getClass()

View File

@ -24,7 +24,7 @@ class MethodHandleFactory {
}
};
MethodHandle forField(Class clazz, String fieldName)
MethodHandle forField(Class<?> clazz, String fieldName)
throws NoSuchMethodException, IllegalAccessException {
MethodHandle methodHandle = getterCache.get(clazz).get(fieldName);
if (methodHandle == null) {

View File

@ -32,10 +32,10 @@ class Serializer {
return serialize((SdkPojo) target);
}
if (target instanceof Collection) {
return serialize((Collection<Object>) target);
return serialize((Collection<?>) target);
}
if (target instanceof Map) {
return serialize(((Map) target).keySet());
return serialize(((Map<?, ?>) target).keySet());
}
// simple type
return target.toString();
@ -61,7 +61,7 @@ class Serializer {
.orElse(null);
}
private String serialize(Collection<Object> collection) {
private String serialize(Collection<?> collection) {
String serialized = collection.stream().map(this::serialize).collect(Collectors.joining(","));
return (StringUtils.isEmpty(serialized) ? null : "[" + serialized + "]");
}

View File

@ -89,8 +89,8 @@ public class ClassHierarchyIterable implements Iterable<Class<?>> {
}
}
private void queueNewInterfaces(Class[] interfaces) {
for (Class clazz : interfaces) {
private void queueNewInterfaces(Class<?>[] interfaces) {
for (Class<?> clazz : interfaces) {
if (queuedInterfaces.add(clazz)) {
classesToExpand.add(clazz);
}

View File

@ -130,7 +130,7 @@ public class OpenTelemetryConnection implements Connection {
throws SQLException {
CallableStatement statement =
delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
return new OpenTelemetryCallableStatement(statement, dbInfo, sql);
return new OpenTelemetryCallableStatement<>(statement, dbInfo, sql);
}
@Override

View File

@ -63,7 +63,7 @@ public final class JettyClientWrapUtil {
return (Response.ResponseListener)
Proxy.newProxyInstance(
listenerClass.getClassLoader(),
interfaces.toArray(new Class[0]),
interfaces.toArray(new Class<?>[0]),
(proxy, method, args) -> {
try (Scope ignored = context.makeCurrent()) {
return method.invoke(listener, args);

View File

@ -112,7 +112,7 @@ public class JettyHttpClient9TracingInterceptor
(Request.RequestListener)
Proxy.newProxyInstance(
listenerClass.getClassLoader(),
interfaces.toArray(new Class[0]),
interfaces.toArray(new Class<?>[0]),
(proxy, method, args) -> {
try (Scope ignored = context.makeCurrent()) {
return method.invoke(listener, args);

View File

@ -153,11 +153,13 @@ class TracingConsumer<K, V> implements Consumer<K, V> {
}
@Override
@Deprecated
public OffsetAndMetadata committed(TopicPartition partition) {
return consumer.committed(partition);
}
@Override
@Deprecated
public OffsetAndMetadata committed(TopicPartition topicPartition, Duration duration) {
return consumer.committed(topicPartition, duration);
}

View File

@ -76,8 +76,7 @@ final class AsyncInstrumentRegistry {
.buildWithCallback(recorderCallback);
return recorderCallback;
});
recorder.addMeasurement(
attributes, new DoubleMeasurementSource(obj, (ToDoubleFunction<Object>) objMetric));
recorder.addMeasurement(attributes, new DoubleMeasurementSource<>(obj, objMetric));
return new AsyncMeasurementHandle(recorder, attributes);
}
@ -112,8 +111,7 @@ final class AsyncInstrumentRegistry {
.buildWithCallback(recorderCallback);
return recorderCallback;
});
recorder.addMeasurement(
attributes, new DoubleMeasurementSource(obj, (ToDoubleFunction<Object>) objMetric));
recorder.addMeasurement(attributes, new DoubleMeasurementSource<>(obj, objMetric));
return new AsyncMeasurementHandle(recorder, attributes);
}
@ -138,8 +136,7 @@ final class AsyncInstrumentRegistry {
.buildWithCallback(recorderCallback);
return recorderCallback;
});
recorder.addMeasurement(
attributes, new LongMeasurementSource(obj, (ToLongFunction<Object>) objMetric));
recorder.addMeasurement(attributes, new LongMeasurementSource<>(obj, objMetric));
return new AsyncMeasurementHandle(recorder, attributes);
}
@ -165,8 +162,7 @@ final class AsyncInstrumentRegistry {
.buildWithCallback(recorderCallback);
return recorderCallback;
});
recorder.addMeasurement(
attributes, new DoubleMeasurementSource(obj, (ToDoubleFunction<Object>) objMetric));
recorder.addMeasurement(attributes, new DoubleMeasurementSource<>(obj, objMetric));
return new AsyncMeasurementHandle(recorder, attributes);
}
@ -194,54 +190,62 @@ final class AsyncInstrumentRegistry {
}
private static final class DoubleMeasurementsRecorder
extends MeasurementsRecorder<DoubleMeasurementSource>
extends MeasurementsRecorder<DoubleMeasurementSource<?>>
implements Consumer<ObservableDoubleMeasurement> {
@Override
public void accept(ObservableDoubleMeasurement measurement) {
measurements.forEach(
(attributes, gauge) -> {
Object obj = gauge.objWeakRef.get();
if (obj != null) {
measurement.record(gauge.metricFunction.applyAsDouble(obj), attributes);
}
});
measurements.forEach((attributes, gauge) -> record(measurement, attributes, gauge));
}
private static <T> void record(
ObservableDoubleMeasurement measurement,
Attributes attributes,
DoubleMeasurementSource<T> gauge) {
T obj = gauge.objWeakRef.get();
if (obj != null) {
measurement.record(gauge.metricFunction.applyAsDouble(obj), attributes);
}
}
}
private static final class LongMeasurementsRecorder
extends MeasurementsRecorder<LongMeasurementSource>
extends MeasurementsRecorder<LongMeasurementSource<?>>
implements Consumer<ObservableLongMeasurement> {
@Override
public void accept(ObservableLongMeasurement measurement) {
measurements.forEach(
(attributes, gauge) -> {
Object obj = gauge.objWeakRef.get();
if (obj != null) {
measurement.record(gauge.metricFunction.applyAsLong(obj), attributes);
}
});
measurements.forEach((attributes, gauge) -> record(measurement, attributes, gauge));
}
private static <T> void record(
ObservableLongMeasurement measurement,
Attributes attributes,
LongMeasurementSource<T> gauge) {
T obj = gauge.objWeakRef.get();
if (obj != null) {
measurement.record(gauge.metricFunction.applyAsLong(obj), attributes);
}
}
}
private static final class DoubleMeasurementSource {
private static final class DoubleMeasurementSource<T> {
private final WeakReference<Object> objWeakRef;
private final ToDoubleFunction<Object> metricFunction;
private final WeakReference<T> objWeakRef;
private final ToDoubleFunction<T> metricFunction;
private DoubleMeasurementSource(@Nullable Object obj, ToDoubleFunction<Object> metricFunction) {
private DoubleMeasurementSource(@Nullable T obj, ToDoubleFunction<T> metricFunction) {
this.objWeakRef = new WeakReference<>(obj);
this.metricFunction = metricFunction;
}
}
private static final class LongMeasurementSource {
private static final class LongMeasurementSource<T> {
private final WeakReference<Object> objWeakRef;
private final ToLongFunction<Object> metricFunction;
private final WeakReference<T> objWeakRef;
private final ToLongFunction<T> metricFunction;
private LongMeasurementSource(@Nullable Object obj, ToLongFunction<Object> metricFunction) {
private LongMeasurementSource(@Nullable T obj, ToLongFunction<T> metricFunction) {
this.objWeakRef = new WeakReference<>(obj);
this.metricFunction = metricFunction;
}

View File

@ -6,7 +6,9 @@
package io.opentelemetry.instrumentation.quartz.v2_0;
import io.opentelemetry.api.OpenTelemetry;
import org.quartz.JobKey;
import org.quartz.JobListener;
import org.quartz.Matcher;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.matchers.EverythingMatcher;
@ -51,7 +53,9 @@ public final class QuartzTracing {
try {
// We must pass a matcher to work around a bug in Quartz 2.0.0. It's unlikely anyone uses
// a version before 2.0.2, but it makes muzzle simple.
scheduler.getListenerManager().addJobListener(jobListener, EverythingMatcher.allJobs());
@SuppressWarnings({"rawtypes", "unchecked"})
Matcher<JobKey>[] matchers = new Matcher[] {EverythingMatcher.allJobs()};
scheduler.getListenerManager().addJobListener(jobListener, matchers);
} catch (SchedulerException e) {
throw new IllegalStateException("Could not add JobListener to Scheduler", e);
}

View File

@ -81,6 +81,8 @@ public final class ReactorAsyncOperationEndStrategy implements AsyncOperationEnd
private abstract class EndOnFirstNotificationConsumer extends AtomicBoolean
implements Runnable, Consumer<Throwable> {
private static final long serialVersionUID = 1L;
private final Context context;
protected EndOnFirstNotificationConsumer(Context context) {

View File

@ -139,6 +139,8 @@ public final class RxJava2AsyncOperationEndStrategy implements AsyncOperationEnd
private abstract class EndOnFirstNotificationConsumer<T> extends AtomicBoolean
implements Action, Consumer<Throwable>, BiConsumer<T, Throwable> {
private static final long serialVersionUID = 1L;
private final Context context;
protected EndOnFirstNotificationConsumer(Context context) {

View File

@ -45,6 +45,7 @@ class TracingParallelFlowable<T> extends ParallelFlowable<T> {
return;
}
int n = subscribers.length;
@SuppressWarnings("rawtypes")
Subscriber<? super T>[] parents = new Subscriber[n];
for (int i = 0; i < n; i++) {
Subscriber<? super T> z = subscribers[i];

View File

@ -139,6 +139,8 @@ public final class RxJava3AsyncOperationEndStrategy implements AsyncOperationEnd
private abstract class EndOnFirstNotificationConsumer<T> extends AtomicBoolean
implements Action, Consumer<Throwable>, BiConsumer<T, Throwable> {
private static final long serialVersionUID = 1L;
private final Context context;
protected EndOnFirstNotificationConsumer(Context context) {

View File

@ -45,6 +45,7 @@ class TracingParallelFlowable<T> extends ParallelFlowable<T> {
return;
}
int n = subscribers.length;
@SuppressWarnings("rawtypes")
Subscriber<? super T>[] parents = new Subscriber[n];
for (int i = 0; i < n; i++) {
Subscriber<? super T> z = subscribers[i];

View File

@ -45,6 +45,7 @@ class TracingParallelFlowable<T> extends ParallelFlowable<T> {
return;
}
int n = subscribers.length;
@SuppressWarnings("rawtypes")
Subscriber<? super T>[] parents = new Subscriber[n];
for (int i = 0; i < n; i++) {
Subscriber<? super T> z = subscribers[i];

View File

@ -23,8 +23,10 @@ enum MessageHeadersGetter implements TextMapGetter<MessageWithChannel> {
@Override
public Iterable<String> keys(MessageWithChannel carrier) {
MessageHeaders headers = carrier.getMessage().getHeaders();
@SuppressWarnings("unchecked")
Map<String, List<String>> nativeHeaders =
headers.get(NativeMessageHeaderAccessor.NATIVE_HEADERS, Map.class);
(Map<String, List<String>>)
headers.get(NativeMessageHeaderAccessor.NATIVE_HEADERS, Map.class);
if (nativeHeaders != null) {
return nativeHeaders.keySet();
}
@ -50,8 +52,10 @@ enum MessageHeadersGetter implements TextMapGetter<MessageWithChannel> {
@Nullable
private static String getNativeHeader(MessageHeaders carrier, String key) {
@SuppressWarnings("unchecked")
Map<String, List<String>> nativeMap =
carrier.get(NativeMessageHeaderAccessor.NATIVE_HEADERS, Map.class);
(Map<String, List<String>>)
carrier.get(NativeMessageHeaderAccessor.NATIVE_HEADERS, Map.class);
if (nativeMap == null) {
return null;
}

View File

@ -29,7 +29,9 @@ enum MessageHeadersSetter implements TextMapSetter<MessageHeaderAccessor> {
private static void setNativeHeader(MessageHeaderAccessor carrier, String key, String value) {
Object nativeMap = carrier.getHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS);
if (nativeMap instanceof Map) {
((Map<String, List<String>>) nativeMap).put(key, singletonList(value));
@SuppressWarnings("unchecked")
Map<String, List<String>> map = ((Map<String, List<String>>) nativeMap);
map.put(key, singletonList(value));
}
}
}

View File

@ -186,9 +186,10 @@ final class TracingChannelInterceptor implements ExecutorChannelInterceptor {
private static void ensureNativeHeadersAreMutable(MessageHeaderAccessor headerAccessor) {
Object nativeMap = headerAccessor.getHeader(NativeMessageHeaderAccessor.NATIVE_HEADERS);
if (nativeMap != null && !(nativeMap instanceof LinkedMultiValueMap)) {
@SuppressWarnings("unchecked")
Map<String, List<String>> map = (Map<String, List<String>>) nativeMap;
headerAccessor.setHeader(
NativeMessageHeaderAccessor.NATIVE_HEADERS,
new LinkedMultiValueMap<>((Map<String, List<String>>) nativeMap));
NativeMessageHeaderAccessor.NATIVE_HEADERS, new LinkedMultiValueMap<>(map));
}
}
@ -250,6 +251,7 @@ final class TracingChannelInterceptor implements ExecutorChannelInterceptor {
// unwrap spring aop proxy
// based on org.springframework.test.util.AopTestUtils#getTargetObject
@SuppressWarnings("unchecked")
public static <T> T unwrapProxy(T candidate) {
try {
if (AopUtils.isAopProxy(candidate) && candidate instanceof Advised) {

View File

@ -18,4 +18,7 @@ dependencies {
implementation("io.opentelemetry:opentelemetry-sdk-metrics")
// autoconfigure is unstable, do not expose as api
implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
// Used by byte-buddy but not brought in as a transitive dependency.
compileOnly("com.google.code.findbugs:annotations")
}

View File

@ -40,6 +40,9 @@ dependencies {
annotationProcessor("com.google.auto.service:auto-service")
compileOnly("com.google.auto.service:auto-service")
// Used by byte-buddy but not brought in as a transitive dependency.
compileOnly("com.google.code.findbugs:annotations")
testImplementation(project(":testing-common"))
testImplementation("com.google.guava:guava")
testImplementation("org.assertj:assertj-core")

View File

@ -17,3 +17,14 @@ dependencies {
otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_1_9)
}
tasks {
compileJava {
with(options) {
// Because this module targets Java 9, we trigger this compiler bug which was fixed but not
// backported to Java 9 compilation.
// https://bugs.openjdk.java.net/browse/JDK-8209058
compilerArgs.add("-Xlint:none")
}
}
}

View File

@ -22,7 +22,9 @@ final class RuntimeFieldBasedImplementationSupplier
getVirtualFieldImplementationClassName(type.getName(), fieldType.getName());
Class<?> contextStoreClass = Class.forName(virtualFieldImplClassName, false, null);
Method method = contextStoreClass.getMethod("getVirtualField", Class.class, Class.class);
return (VirtualField<U, F>) method.invoke(null, type, fieldType);
@SuppressWarnings("unchecked")
VirtualField<U, F> field = (VirtualField<U, F>) method.invoke(null, type, fieldType);
return field;
} catch (ClassNotFoundException exception) {
throw new IllegalStateException("VirtualField not found", exception);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exception) {

View File

@ -303,7 +303,7 @@ final class VirtualFieldImplementationsGenerator {
}
}
public static VirtualField getVirtualField(Class keyClass, Class contextClass) {
public static VirtualField<?, ?> getVirtualField(Class<?> keyClass, Class<?> contextClass) {
// We do not actually check the keyClass here - but that should be fine since compiler would
// check things for us.
return INSTANCE;

View File

@ -21,6 +21,9 @@ dependencies {
implementation(project(":javaagent-extension-api"))
implementation("org.slf4j:slf4j-api")
// Used by byte-buddy but not brought in as a transitive dependency.
compileOnly("com.google.code.findbugs:annotations")
testImplementation(project(":testing-common"))
testImplementation("com.google.guava:guava")
testImplementation("org.assertj:assertj-core:3.19.0")

View File

@ -6,6 +6,8 @@
package io.opentelemetry.javaagent.tooling.muzzle;
final class MuzzleCompilationException extends RuntimeException {
private static final long serialVersionUID = 1L;
MuzzleCompilationException(String message) {
super(message);
}

View File

@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.test.utils;
public final class ExceptionUtils {
@SuppressWarnings("unchecked")
static RuntimeException sneakyThrow(Throwable t) {
if (t == null) {
throw new NullPointerException("t");
@ -15,7 +16,7 @@ public final class ExceptionUtils {
}
// Exactly what we want
@SuppressWarnings("TypeParameterUnusedInFormals")
@SuppressWarnings({"TypeParameterUnusedInFormals", "unchecked"})
private static <T extends Throwable> T sneakyThrow0(Throwable t) throws T {
throw (T) t;
}

View File

@ -70,6 +70,7 @@ public abstract class InstrumentationTestRunner {
}
@SafeVarargs
@SuppressWarnings("varargs")
public final void waitAndAssertTraces(Consumer<TraceAssert>... assertions) {
waitAndAssertTraces(Arrays.asList(assertions));
}

View File

@ -398,7 +398,7 @@ public abstract class AbstractHttpClientTest<REQUEST> {
for (int i = 0; i < options.maxRedirects; i++) {
assertions.add(span -> assertServerSpan(span).hasParent(trace.getSpan(0)));
}
trace.hasSpansSatisfyingExactly(assertions.toArray(new Consumer[0]));
trace.hasSpansSatisfyingExactly(assertions);
});
}
@ -1098,7 +1098,7 @@ public abstract class AbstractHttpClientTest<REQUEST> {
}
private int doRequestWithExistingTracingHeaders(String method, URI uri) throws Exception {
Map<String, String> headers = new HashMap();
Map<String, String> headers = new HashMap<>();
for (String field :
testing.getOpenTelemetry().getPropagators().getTextMapPropagator().fields()) {
headers.put(field, "12345789");