Enable error prone's UnusedVariable check (#6217)
* Enable error prone's UnusedVariable check * Spotless
This commit is contained in:
parent
c1c108c870
commit
8fac01e736
|
@ -86,10 +86,6 @@ tasks {
|
||||||
disable("JdkObsolete")
|
disable("JdkObsolete")
|
||||||
disable("JavaUtilDate")
|
disable("JavaUtilDate")
|
||||||
|
|
||||||
// Storing into a variable in onEnter triggers this unfortunately.
|
|
||||||
// TODO(anuraaga): Only disable for auto instrumentation project.
|
|
||||||
disable("UnusedVariable")
|
|
||||||
|
|
||||||
// TODO(anuraaga): Remove this, we use this pattern in several tests and it will mean
|
// TODO(anuraaga): Remove this, we use this pattern in several tests and it will mean
|
||||||
// some moving.
|
// some moving.
|
||||||
disable("DefaultPackage")
|
disable("DefaultPackage")
|
||||||
|
|
|
@ -134,11 +134,11 @@ class AttributeBindingFactory {
|
||||||
}
|
}
|
||||||
if (componentType == Integer.class) {
|
if (componentType == Integer.class) {
|
||||||
AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name);
|
AttributeKey<List<Long>> key = AttributeKey.longArrayKey(name);
|
||||||
return mappedListBinding(Integer.class, key, Integer::longValue);
|
return mappedListBinding(key, Integer::longValue);
|
||||||
}
|
}
|
||||||
if (componentType == Float.class) {
|
if (componentType == Float.class) {
|
||||||
AttributeKey<List<Double>> key = AttributeKey.doubleArrayKey(name);
|
AttributeKey<List<Double>> key = AttributeKey.doubleArrayKey(name);
|
||||||
return mappedListBinding(Float.class, key, Float::doubleValue);
|
return mappedListBinding(key, Float::doubleValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultListBinding(name);
|
return defaultListBinding(name);
|
||||||
|
@ -308,7 +308,7 @@ class AttributeBindingFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T, U> AttributeBinding mappedListBinding(
|
private static <T, U> AttributeBinding mappedListBinding(
|
||||||
Class<T> fromClass, AttributeKey<List<U>> key, Function<T, U> mapping) {
|
AttributeKey<List<U>> key, Function<T, U> mapping) {
|
||||||
return (setter, arg) -> {
|
return (setter, arg) -> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<T> list = (List<T>) arg;
|
List<T> list = (List<T>) arg;
|
||||||
|
@ -331,7 +331,7 @@ class AttributeBindingFactory {
|
||||||
|
|
||||||
private static AttributeBinding defaultListBinding(String name) {
|
private static AttributeBinding defaultListBinding(String name) {
|
||||||
AttributeKey<List<String>> key = AttributeKey.stringArrayKey(name);
|
AttributeKey<List<String>> key = AttributeKey.stringArrayKey(name);
|
||||||
return mappedListBinding(Object.class, key, Object::toString);
|
return mappedListBinding(key, Object::toString);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AttributeBinding defaultBinding(String name) {
|
private static AttributeBinding defaultBinding(String name) {
|
||||||
|
|
|
@ -22,7 +22,6 @@ import io.opentelemetry.instrumentation.testing.junit.http.HttpServerTestOptions
|
||||||
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
import io.opentelemetry.instrumentation.testing.junit.http.ServerEndpoint;
|
||||||
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
|
import io.opentelemetry.sdk.testing.assertj.SpanDataAssert;
|
||||||
import io.opentelemetry.sdk.trace.data.StatusData;
|
import io.opentelemetry.sdk.trace.data.StatusData;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -67,21 +66,24 @@ public class GrailsTest extends AbstractHttpServerTest<ConfigurableApplicationCo
|
||||||
static class TestApplication extends GrailsAutoConfiguration {
|
static class TestApplication extends GrailsAutoConfiguration {
|
||||||
static ConfigurableApplicationContext start(int port, String contextPath) {
|
static ConfigurableApplicationContext start(int port, String contextPath) {
|
||||||
GrailsApp grailsApp = new GrailsApp(TestApplication.class);
|
GrailsApp grailsApp = new GrailsApp(TestApplication.class);
|
||||||
// context path configuration property name changes between spring boot versions
|
|
||||||
String contextPathKey;
|
|
||||||
try {
|
|
||||||
Method method = ServerProperties.class.getDeclaredMethod("getServlet");
|
|
||||||
contextPathKey = "server.servlet.contextPath";
|
|
||||||
} catch (NoSuchMethodException ignore) {
|
|
||||||
contextPathKey = "server.context-path";
|
|
||||||
}
|
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
properties.put("server.port", port);
|
properties.put("server.port", port);
|
||||||
properties.put(contextPathKey, contextPath);
|
properties.put(getContextPathKey(), contextPath);
|
||||||
grailsApp.setDefaultProperties(properties);
|
grailsApp.setDefaultProperties(properties);
|
||||||
return grailsApp.run();
|
return grailsApp.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ReturnValueIgnored")
|
||||||
|
private static String getContextPathKey() {
|
||||||
|
// context path configuration property name changes between spring boot versions
|
||||||
|
try {
|
||||||
|
ServerProperties.class.getDeclaredMethod("getServlet");
|
||||||
|
return "server.servlet.contextPath";
|
||||||
|
} catch (NoSuchMethodException ignore) {
|
||||||
|
return "server.context-path";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
@Override
|
@Override
|
||||||
public Collection<Class> classes() {
|
public Collection<Class> classes() {
|
||||||
|
|
|
@ -1192,7 +1192,6 @@ public abstract class AbstractGrpcTest {
|
||||||
GreeterGrpc.GreeterStub client = GreeterGrpc.newStub(channel);
|
GreeterGrpc.GreeterStub client = GreeterGrpc.newStub(channel);
|
||||||
|
|
||||||
IllegalStateException thrown = new IllegalStateException("illegal");
|
IllegalStateException thrown = new IllegalStateException("illegal");
|
||||||
AtomicReference<Helloworld.Response> response = new AtomicReference<>();
|
|
||||||
AtomicReference<Throwable> error = new AtomicReference<>();
|
AtomicReference<Throwable> error = new AtomicReference<>();
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
testing()
|
testing()
|
||||||
|
|
|
@ -76,7 +76,6 @@ public enum JdbcConnectionUrlParser {
|
||||||
@Override
|
@Override
|
||||||
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
|
DbInfo.Builder doParse(String jdbcUrl, DbInfo.Builder builder) {
|
||||||
String serverName = "";
|
String serverName = "";
|
||||||
Integer port = null;
|
|
||||||
|
|
||||||
int hostIndex = jdbcUrl.indexOf("jtds:sqlserver://");
|
int hostIndex = jdbcUrl.indexOf("jtds:sqlserver://");
|
||||||
if (hostIndex < 0) {
|
if (hostIndex < 0) {
|
||||||
|
|
|
@ -34,6 +34,7 @@ public class JspCompilationContextInstrumentation implements TypeInstrumentation
|
||||||
JspCompilationContextInstrumentation.class.getName() + "$JasperJspCompilationContext");
|
JspCompilationContextInstrumentation.class.getName() + "$JasperJspCompilationContext");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static class JasperJspCompilationContext {
|
public static class JasperJspCompilationContext {
|
||||||
|
|
||||||
@Advice.OnMethodEnter(suppress = Throwable.class)
|
@Advice.OnMethodEnter(suppress = Throwable.class)
|
||||||
|
|
|
@ -37,6 +37,7 @@ public class BootstrapInstrumentation implements TypeInstrumentation {
|
||||||
BootstrapInstrumentation.class.getName() + "$ConnectAdvice");
|
BootstrapInstrumentation.class.getName() + "$ConnectAdvice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static class ConnectAdvice {
|
public static class ConnectAdvice {
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
public static void startConnect(
|
public static void startConnect(
|
||||||
|
|
|
@ -162,7 +162,7 @@ public final class ContextPropagationOperator {
|
||||||
implements BiFunction<Scannable, CoreSubscriber<? super T>, CoreSubscriber<? super T>> {
|
implements BiFunction<Scannable, CoreSubscriber<? super T>, CoreSubscriber<? super T>> {
|
||||||
|
|
||||||
/** Holds reference to strategy to prevent it from being collected. */
|
/** Holds reference to strategy to prevent it from being collected. */
|
||||||
@SuppressWarnings("FieldCanBeLocal")
|
@SuppressWarnings({"FieldCanBeLocal", "UnusedVariable"})
|
||||||
private final ReactorAsyncOperationEndStrategy asyncOperationEndStrategy;
|
private final ReactorAsyncOperationEndStrategy asyncOperationEndStrategy;
|
||||||
|
|
||||||
public Lifter(ReactorAsyncOperationEndStrategy asyncOperationEndStrategy) {
|
public Lifter(ReactorAsyncOperationEndStrategy asyncOperationEndStrategy) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import org.apache.tapestry5.annotations.Parameter;
|
||||||
import org.apache.tapestry5.annotations.Property;
|
import org.apache.tapestry5.annotations.Property;
|
||||||
import org.apache.tapestry5.ioc.annotations.Inject;
|
import org.apache.tapestry5.ioc.annotations.Inject;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class Layout {
|
public class Layout {
|
||||||
@Inject private ComponentResources resources;
|
@Inject private ComponentResources resources;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,9 @@ package io.opentelemetry.javaagent.tooling.bytebuddy;
|
||||||
|
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class BadAdvice {
|
public class BadAdvice {
|
||||||
|
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
public static void throwAnException(@Advice.Return(readOnly = false) boolean returnVal) {
|
public static void throwAnException(@Advice.Return(readOnly = false) boolean returnVal) {
|
||||||
returnVal = true;
|
returnVal = true;
|
||||||
|
|
|
@ -169,7 +169,7 @@ public class HelperInjector implements Transformer {
|
||||||
ClassLoader classLoader,
|
ClassLoader classLoader,
|
||||||
JavaModule module) {
|
JavaModule module) {
|
||||||
if (!helperClassNames.isEmpty()) {
|
if (!helperClassNames.isEmpty()) {
|
||||||
injectHelperClasses(typeDescription, classLoader, module);
|
injectHelperClasses(typeDescription, classLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (classLoader != null && helpersSource != null && !helperResources.isEmpty()) {
|
if (classLoader != null && helpersSource != null && !helperResources.isEmpty()) {
|
||||||
|
@ -226,8 +226,7 @@ public class HelperInjector implements Transformer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void injectHelperClasses(
|
private void injectHelperClasses(TypeDescription typeDescription, ClassLoader classLoader) {
|
||||||
TypeDescription typeDescription, ClassLoader classLoader, JavaModule module) {
|
|
||||||
classLoader = maskNullClassLoader(classLoader);
|
classLoader = maskNullClassLoader(classLoader);
|
||||||
if (classLoader == BOOTSTRAP_CLASSLOADER_PLACEHOLDER && instrumentation == null) {
|
if (classLoader == BOOTSTRAP_CLASSLOADER_PLACEHOLDER && instrumentation == null) {
|
||||||
logger.log(
|
logger.log(
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
package io.opentelemetry.javaagent.tooling.muzzle;
|
package io.opentelemetry.javaagent.tooling.muzzle;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class DeclaredFieldTestClass {
|
public class DeclaredFieldTestClass {
|
||||||
public static class Advice {
|
public static class Advice {
|
||||||
public void instrument() {
|
public void instrument() {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
package muzzle;
|
package muzzle;
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedMethod", "MethodCanBeStatic"})
|
@SuppressWarnings("unused")
|
||||||
public class HelperReferenceWrapperTestClasses {
|
public class HelperReferenceWrapperTestClasses {
|
||||||
interface Interface1 {
|
interface Interface1 {
|
||||||
void foo();
|
void foo();
|
||||||
|
@ -21,6 +21,7 @@ public class HelperReferenceWrapperTestClasses {
|
||||||
|
|
||||||
static void staticMethodsAreIgnored() {}
|
static void staticMethodsAreIgnored() {}
|
||||||
|
|
||||||
|
@SuppressWarnings("MethodCanBeStatic")
|
||||||
private void privateMethodsToo() {}
|
private void privateMethodsToo() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,10 @@ import io.opentelemetry.instrumentation.OtherTestHelperClasses;
|
||||||
import io.opentelemetry.instrumentation.TestHelperClasses.Helper;
|
import io.opentelemetry.instrumentation.TestHelperClasses.Helper;
|
||||||
import net.bytebuddy.asm.Advice;
|
import net.bytebuddy.asm.Advice;
|
||||||
|
|
||||||
@SuppressWarnings("ClassNamedLikeTypeParameter")
|
@SuppressWarnings("unused")
|
||||||
public class TestClasses {
|
public class TestClasses {
|
||||||
|
|
||||||
|
@SuppressWarnings("ClassNamedLikeTypeParameter")
|
||||||
public static class MethodBodyAdvice {
|
public static class MethodBodyAdvice {
|
||||||
@SuppressWarnings("ReturnValueIgnored")
|
@SuppressWarnings("ReturnValueIgnored")
|
||||||
@Advice.OnMethodEnter
|
@Advice.OnMethodEnter
|
||||||
|
@ -46,7 +47,7 @@ public class TestClasses {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"UnusedMethod", "MethodCanBeStatic"})
|
@SuppressWarnings("MethodCanBeStatic")
|
||||||
private void privateStuff() {}
|
private void privateStuff() {}
|
||||||
|
|
||||||
protected void protectedMethod() {}
|
protected void protectedMethod() {}
|
||||||
|
|
|
@ -244,7 +244,7 @@ public class WindowsTestContainerManager extends AbstractTestContainerManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ContainerLogHandler consumeLogs(String containerId, Waiter waiter, Logger logger) {
|
private void registerLogListener(String containerId, Waiter waiter, Logger logger) {
|
||||||
ContainerLogFrameConsumer consumer = new ContainerLogFrameConsumer();
|
ContainerLogFrameConsumer consumer = new ContainerLogFrameConsumer();
|
||||||
waiter.configureLogger(consumer);
|
waiter.configureLogger(consumer);
|
||||||
|
|
||||||
|
@ -257,7 +257,6 @@ public class WindowsTestContainerManager extends AbstractTestContainerManager {
|
||||||
.exec(consumer);
|
.exec(consumer);
|
||||||
|
|
||||||
consumer.addListener(new Slf4jDockerLogLineListener(logger));
|
consumer.addListener(new Slf4jDockerLogLineListener(logger));
|
||||||
return consumer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int extractMappedPort(Container container, int internalPort) {
|
private static int extractMappedPort(Container container, int internalPort) {
|
||||||
|
@ -295,11 +294,11 @@ public class WindowsTestContainerManager extends AbstractTestContainerManager {
|
||||||
prepareAction.accept(containerId);
|
prepareAction.accept(containerId);
|
||||||
|
|
||||||
client.startContainerCmd(containerId).exec();
|
client.startContainerCmd(containerId).exec();
|
||||||
ContainerLogHandler logHandler = consumeLogs(containerId, waiter, logger);
|
registerLogListener(containerId, waiter, logger);
|
||||||
|
|
||||||
InspectContainerResponse inspectResponse =
|
InspectContainerResponse inspectResponse =
|
||||||
inspect ? client.inspectContainerCmd(containerId).exec() : null;
|
inspect ? client.inspectContainerCmd(containerId).exec() : null;
|
||||||
Container container = new Container(imageName, containerId, logHandler, inspectResponse);
|
Container container = new Container(imageName, containerId, inspectResponse);
|
||||||
|
|
||||||
waiter.waitFor(container);
|
waiter.waitFor(container);
|
||||||
return container;
|
return container;
|
||||||
|
@ -318,17 +317,12 @@ public class WindowsTestContainerManager extends AbstractTestContainerManager {
|
||||||
private static class Container {
|
private static class Container {
|
||||||
public final String imageName;
|
public final String imageName;
|
||||||
public final String containerId;
|
public final String containerId;
|
||||||
public final ContainerLogHandler logConsumer;
|
|
||||||
public final InspectContainerResponse inspectResponse;
|
public final InspectContainerResponse inspectResponse;
|
||||||
|
|
||||||
private Container(
|
private Container(
|
||||||
String imageName,
|
String imageName, String containerId, InspectContainerResponse inspectResponse) {
|
||||||
String containerId,
|
|
||||||
ContainerLogHandler logConsumer,
|
|
||||||
InspectContainerResponse inspectResponse) {
|
|
||||||
this.imageName = imageName;
|
this.imageName = imageName;
|
||||||
this.containerId = containerId;
|
this.containerId = containerId;
|
||||||
this.logConsumer = logConsumer;
|
|
||||||
this.inspectResponse = inspectResponse;
|
this.inspectResponse = inspectResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class ResourceLevelInstrumentation implements TypeInstrumentation {
|
||||||
named("toString"), this.getClass().getName() + "$ToStringAdvice");
|
named("toString"), this.getClass().getName() + "$ToStringAdvice");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public static class ToStringAdvice {
|
public static class ToStringAdvice {
|
||||||
@Advice.OnMethodExit(suppress = Throwable.class)
|
@Advice.OnMethodExit(suppress = Throwable.class)
|
||||||
static void toStringReplace(@Advice.Return(readOnly = false) String ret) {
|
static void toStringReplace(@Advice.Return(readOnly = false) String ret) {
|
||||||
|
|
|
@ -315,7 +315,6 @@ public abstract class AbstractHttpClientTest<REQUEST> {
|
||||||
|
|
||||||
testing.waitAndAssertTraces(
|
testing.waitAndAssertTraces(
|
||||||
trace -> {
|
trace -> {
|
||||||
List<List<SpanData>> traces = testing.traces();
|
|
||||||
trace.hasSpansSatisfyingExactly(
|
trace.hasSpansSatisfyingExactly(
|
||||||
span -> assertClientSpan(span, uri, method, 200).hasNoParent(),
|
span -> assertClientSpan(span, uri, method, 200).hasNoParent(),
|
||||||
span -> assertServerSpan(span).hasParent(trace.getSpan(0)));
|
span -> assertServerSpan(span).hasParent(trace.getSpan(0)));
|
||||||
|
|
Loading…
Reference in New Issue