Use singletonMap for single entry maps
MODIFY
dd-java-agent/instrumentation/hibernate/core-4.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_3/SessionInstrumentation.java
dd-java-agent/instrumentation/hibernate/core-4.3/src/main/java/datadog/trace/instrumentation/hibernate/core/v4_3/SessionInstrumentation.java
@@ -3,6 +3,7 @@ package datadog.trace.instrumentation.hibernate.core.v4_3;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.hasInterface;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.returns;
@@ -60,13 +61,9 @@ public class SessionInstrumentation extends Instrumenter.Default {
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
- final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
-
- transformers.put(
+ return singletonMap(
isMethod().and(returns(hasInterface(named("org.hibernate.procedure.ProcedureCall")))),
SessionInstrumentation.class.getName() + "$GetProcedureCallAdvice");
-
- return transformers;
}
public static class GetProcedureCallAdvice {

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/CallableInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/CallableInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -12,8 +13,6 @@ import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.java.concurrent.AdviceUtils;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import lombok.extern.slf4j.Slf4j;
@@ -38,18 +37,14 @@ public final class CallableInstrumentation extends Instrumenter.Default {
@Override
public Map<String, String> contextStore() {
- final Map<String, String> map = new HashMap<>();
- map.put(Callable.class.getName(), State.class.getName());
- return Collections.unmodifiableMap(map);
+ return singletonMap(Callable.class.getName(), State.class.getName());
}
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
- final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
- transformers.put(
+ return singletonMap(
named("call").and(takesArguments(0)).and(isPublic()),
CallableInstrumentation.class.getName() + "$CallableAdvice");
- return transformers;
}
public static class CallableAdvice {

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/FutureInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/FutureInstrumentation.java
@@ -13,7 +13,6 @@ import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.Future;
@@ -92,9 +91,7 @@ public final class FutureInstrumentation extends Instrumenter.Default {
@Override
public Map<String, String> contextStore() {
- final Map<String, String> map = new HashMap<>();
- map.put(Future.class.getName(), State.class.getName());
- return Collections.unmodifiableMap(map);
+ return singletonMap(Future.class.getName(), State.class.getName());
}
@Override

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/JavaForkJoinTaskInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/JavaForkJoinTaskInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
@@ -55,11 +56,9 @@ public final class JavaForkJoinTaskInstrumentation extends Instrumenter.Default
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
- final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
- transformers.put(
+ return singletonMap(
named("exec").and(takesArguments(0)).and(not(isAbstract())),
JavaForkJoinTaskInstrumentation.class.getName() + "$ForkJoinTaskAdvice");
- return transformers;
}
public static class ForkJoinTaskAdvice {

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/RunnableInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/RunnableInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.implementsInterface;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
@@ -12,8 +13,6 @@ import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.java.concurrent.AdviceUtils;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import net.bytebuddy.asm.Advice;
@@ -37,18 +36,14 @@ public final class RunnableInstrumentation extends Instrumenter.Default {
@Override
public Map<String, String> contextStore() {
- final Map<String, String> map = new HashMap<>();
- map.put(Runnable.class.getName(), State.class.getName());
- return Collections.unmodifiableMap(map);
+ return singletonMap(Runnable.class.getName(), State.class.getName());
}
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
- final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
- transformers.put(
+ return singletonMap(
named("run").and(takesArguments(0)).and(isPublic()),
RunnableInstrumentation.class.getName() + "$RunnableAdvice");
- return transformers;
}
public static class RunnableAdvice {

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaExecutorInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaExecutorInstrumentation.java
package datadog.trace.instrumentation.java.concurrent;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.activeScope;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.nameMatches;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -12,7 +13,6 @@ import datadog.trace.bootstrap.InstrumentationContext;
import datadog.trace.bootstrap.instrumentation.java.concurrent.ExecutorInstrumentationUtils;
import datadog.trace.bootstrap.instrumentation.java.concurrent.State;
import datadog.trace.context.TraceScope;
-import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executor;
@@ -32,8 +32,7 @@ public final class ScalaExecutorInstrumentation extends AbstractExecutorInstrume
@Override
public Map<String, String> contextStore() {
- return Collections.singletonMap(
- ScalaForkJoinTaskInstrumentation.TASK_CLASS_NAME, State.class.getName());
+ return singletonMap(ScalaForkJoinTaskInstrumentation.TASK_CLASS_NAME, State.class.getName());
}
@Override

MODIFY
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaForkJoinTaskInstrumentation.java
dd-java-agent/instrumentation/java-concurrent/src/main/java/datadog/trace/instrumentation/java/concurrent/ScalaForkJoinTaskInstrumentation.java
@@ -2,6 +2,7 @@ package datadog.trace.instrumentation.java.concurrent;
import static datadog.trace.agent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static datadog.trace.agent.tooling.bytebuddy.matcher.DDElementMatchers.extendsClass;
+import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isAbstract;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.not;
@@ -64,11 +65,9 @@ public final class ScalaForkJoinTaskInstrumentation extends Instrumenter.Default
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
- final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
- transformers.put(
+ return singletonMap(
named("exec").and(takesArguments(0)).and(not(isAbstract())),
ScalaForkJoinTaskInstrumentation.class.getName() + "$ForkJoinTaskAdvice");
- return transformers;
}
public static class ForkJoinTaskAdvice {

MODIFY
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java
dd-java-agent/instrumentation/trace-annotation/src/main/java/datadog/trace/instrumentation/trace_annotation/TraceConfigInstrumentation.java
@@ -11,7 +11,6 @@ import datadog.trace.agent.tooling.Instrumenter;
import datadog.trace.api.Config;
import datadog.trace.api.Trace;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
@@ -155,9 +154,8 @@ public class TraceConfigInstrumentation implements Instrumenter {
}
}
- final Map<ElementMatcher<? super MethodDescription>, String> transformers = new HashMap<>();
- transformers.put(methodMatchers, packageName + ".TraceAdvice");
- return transformers;
+ return Collections.<ElementMatcher<? super MethodDescription>, String>singletonMap(
+ methodMatchers, packageName + ".TraceAdvice");
}
}
}

Use singletonMap for single entry maps