Skip to content

Commit 308faa1

Browse files
committed
Fix PMD findings.
1 parent 784af1e commit 308faa1

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

powertools-metrics/src/main/java/software/amazon/lambda/powertools/metrics/internal/RequestScopedMetricsProxy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.HashMap;
1919
import java.util.Optional;
2020
import java.util.concurrent.ConcurrentHashMap;
21+
import java.util.concurrent.ConcurrentMap;
2122
import java.util.concurrent.atomic.AtomicBoolean;
2223
import java.util.concurrent.atomic.AtomicReference;
2324
import java.util.function.Consumer;
@@ -33,7 +34,7 @@
3334

3435
public class RequestScopedMetricsProxy implements Metrics {
3536
private static final String DEFAULT_TRACE_ID = "DEFAULT";
36-
private final ConcurrentHashMap<String, Metrics> metricsMap = new ConcurrentHashMap<>();
37+
private final ConcurrentMap<String, Metrics> metricsMap = new ConcurrentHashMap<>();
3738
private final MetricsProvider provider;
3839
private final AtomicReference<String> initialNamespace = new AtomicReference<>();
3940
private final AtomicReference<DimensionSet> initialDefaultDimensions = new AtomicReference<>();

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/ConfigurationPrecedenceTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import com.fasterxml.jackson.databind.ObjectMapper;
3434

3535
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
36-
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
3736
import software.amazon.lambda.powertools.common.stubs.TestLambdaContext;
37+
import software.amazon.lambda.powertools.metrics.model.MetricUnit;
3838

3939
/**
4040
* Tests to verify the hierarchy of precedence for configuration:
@@ -44,7 +44,7 @@
4444
*/
4545
class ConfigurationPrecedenceTest {
4646

47-
private final PrintStream standardOut = System.out;
47+
private static final PrintStream STANDARD_OUT = System.out;
4848
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
4949
private final ObjectMapper objectMapper = new ObjectMapper();
5050

@@ -65,7 +65,7 @@ void setUp() throws Exception {
6565

6666
@AfterEach
6767
void tearDown() throws Exception {
68-
System.setOut(standardOut);
68+
System.setOut(STANDARD_OUT);
6969

7070
// Reset the singleton state between tests
7171
java.lang.reflect.Field field = MetricsFactory.class.getDeclaredField("metricsProxy");
@@ -183,7 +183,7 @@ void shouldUseDefaultsWhenNoConfiguration() throws Exception {
183183
assertThat(rootNode.has("Service")).isFalse();
184184
}
185185

186-
private static class HandlerWithMetricsAnnotation implements RequestHandler<Map<String, Object>, String> {
186+
private static final class HandlerWithMetricsAnnotation implements RequestHandler<Map<String, Object>, String> {
187187
@Override
188188
@FlushMetrics(namespace = "AnnotationNamespace", service = "AnnotationService")
189189
public String handleRequest(Map<String, Object> input, Context context) {
@@ -193,7 +193,8 @@ public String handleRequest(Map<String, Object> input, Context context) {
193193
}
194194
}
195195

196-
private static class HandlerWithDefaultMetricsAnnotation implements RequestHandler<Map<String, Object>, String> {
196+
private static final class HandlerWithDefaultMetricsAnnotation
197+
implements RequestHandler<Map<String, Object>, String> {
197198
@Override
198199
@FlushMetrics
199200
public String handleRequest(Map<String, Object> input, Context context) {

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/MetricsBuilderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
class MetricsBuilderTest {
3737

38-
private final PrintStream standardOut = System.out;
38+
private static final PrintStream STANDARD_OUT = System.out;
3939
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
4040
private final ObjectMapper objectMapper = new ObjectMapper();
4141

@@ -46,7 +46,7 @@ void setUp() {
4646

4747
@AfterEach
4848
void tearDown() throws Exception {
49-
System.setOut(standardOut);
49+
System.setOut(STANDARD_OUT);
5050

5151
// Reset the singleton state between tests
5252
java.lang.reflect.Field field = MetricsFactory.class.getDeclaredField("metricsProxy");

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/MetricsFactoryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class MetricsFactoryTest {
4141
private static final String TEST_NAMESPACE = "TestNamespace";
4242
private static final String TEST_SERVICE = "TestService";
4343

44-
private final PrintStream standardOut = System.out;
44+
private static final PrintStream STANDARD_OUT = System.out;
4545
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
4646
private final ObjectMapper objectMapper = new ObjectMapper();
4747

@@ -62,7 +62,7 @@ void setUp() throws Exception {
6262

6363
@AfterEach
6464
void tearDown() throws Exception {
65-
System.setOut(standardOut);
65+
System.setOut(STANDARD_OUT);
6666
System.clearProperty(LambdaConstants.XRAY_TRACE_HEADER);
6767

6868
// Reset the singleton state between tests

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspectTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
class LambdaMetricsAspectTest {
4343

44-
private final PrintStream standardOut = System.out;
44+
private static final PrintStream STANDARD_OUT = System.out;
4545
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
4646
private final ObjectMapper objectMapper = new ObjectMapper();
4747

@@ -62,7 +62,7 @@ void setUp() throws Exception {
6262

6363
@AfterEach
6464
void tearDown() throws Exception {
65-
System.setOut(standardOut);
65+
System.setOut(STANDARD_OUT);
6666

6767
// Reset the singleton state between tests
6868
java.lang.reflect.Field field = MetricsFactory.class.getDeclaredField("metricsProxy");
@@ -216,7 +216,7 @@ void shouldUseCustomFunctionNameWhenProvidedForColdStartMetric() throws Exceptio
216216
JsonNode dimensions = coldStartNode.get("_aws").get("CloudWatchMetrics").get(0).get("Dimensions").get(0);
217217
boolean hasFunctionName = false;
218218
for (JsonNode dimension : dimensions) {
219-
if (dimension.asText().equals("FunctionName")) {
219+
if ("FunctionName".equals(dimension.asText())) {
220220
hasFunctionName = true;
221221
break;
222222
}

0 commit comments

Comments
 (0)