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

Fix some java lint warnings #5120

Merged
merged 6 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions instrumentation-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static int ceilingNextPowerOfTwo(int x) {
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;
Expand Down Expand Up @@ -1110,7 +1110,7 @@ boolean isDead() {
*/
@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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
* 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
Expand Down Expand Up @@ -424,26 +425,26 @@ public void remove() {
/** 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>> {
/** 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();
/**
* 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);
/** 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();
/**
* 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);
/** Sets the next element or <tt>null</tt> if there is no link. */
void setNext(T next);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public InstrumenterBuilder<REQUEST, RESPONSE> addAttributesExtractors(
}

/** 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
final class UnsafeAttributes extends HashMap<AttributeKey<?>, Object>
implements Attributes, AttributesBuilder {

private static final long serialVersionUID = 1L;

// Attributes

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private static final class CacheBasedVirtualFieldSupplier implements VirtualFiel
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change, @anuraaga ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since NetPeerAttributes is deprecated and can't be used in import statement

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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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;
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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;
Expand Down Expand Up @@ -49,7 +48,9 @@ public void setNetPeer(SpanBuilder span, @Nullable InetSocketAddress remoteConne
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) {
Expand Down Expand Up @@ -79,7 +80,10 @@ public void setNetPeer(Span span, String peerName, String peerIp, int port) {
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public 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) {
Expand All @@ -45,7 +45,7 @@ static Object map(APIGatewayProxyRequestEvent event, Class clazz) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public TracingRequestWrapper() {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -39,14 +39,15 @@ protected TracingRequestWrapperBase(BiFunction<I, Class, Object> parameterMapper
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();
this.parameterMapper = parameterMapper;
}

@Override
@SuppressWarnings("unchecked")
protected O doHandleRequest(I input, Context context) {
Object[] parameters = LambdaParameters.toArray(targetMethod, input, context, parameterMapper);
O result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ static Map<String, String> ofStream(InputStream inputStream) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected ConcurrentHashMap<String, MethodHandle> computeValue(Class<?> type) {
}
};

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ String serialize(Object target) {
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();
Expand All @@ -61,7 +61,7 @@ private static String serialize(SdkPojo sdkPojo) {
.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 + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ private void calculateNextIfNecessary() {
}
}

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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public CallableStatement prepareCall(
throws SQLException {
CallableStatement statement =
delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
return new OpenTelemetryCallableStatement(statement, dbInfo, sql);
return new OpenTelemetryCallableStatement<>(statement, dbInfo, sql);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private static Response.ResponseListener wrapTheListener(
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);
Expand Down
Loading