Skip to content

Commit d925b12

Browse files
author
Pankaj Agrawal
committed
chore: Fix/Ignore spotbugs violations
1 parent aad173b commit d925b12

4 files changed

Lines changed: 100 additions & 5 deletions

File tree

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@
418418
</executions>
419419
<configuration>
420420
<xmlOutput>true</xmlOutput>
421+
<excludeFilterFile>../spotbugs-exclude.xml</excludeFilterFile>
421422
</configuration>
422423
</plugin>
423424
<plugin>

powertools-sqs/src/main/java/software/amazon/lambda/powertools/sqs/SQSBatchProcessingException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package software.amazon.lambda.powertools.sqs;
22

33
import java.util.ArrayList;
4+
import java.util.Collections;
45
import java.util.List;
56

67
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
78

89
import static com.amazonaws.services.lambda.runtime.events.SQSEvent.SQSMessage;
10+
import static java.util.Collections.*;
911
import static java.util.stream.Collectors.joining;
1012

1113
/**
@@ -48,23 +50,23 @@ public <T> SQSBatchProcessingException(final List<Exception> exceptions,
4850
* @return List of exceptions that occurred while processing messages
4951
*/
5052
public List<Exception> getExceptions() {
51-
return exceptions;
53+
return unmodifiableList(exceptions);
5254
}
5355

5456
/**
5557
* List of returns from {@link SqsMessageHandler#process(SQSMessage)} that were successfully processed.
5658
* @return List of returns from successfully processed messages
5759
*/
5860
public List<Object> successMessageReturnValues() {
59-
return returnValues;
61+
return unmodifiableList(returnValues);
6062
}
6163

6264
/**
6365
* Details of {@link SQSMessage} that failed in {@link SqsMessageHandler#process(SQSMessage)}
6466
* @return List of failed messages
6567
*/
6668
public List<SQSMessage> getFailures() {
67-
return failures;
69+
return unmodifiableList(failures);
6870
}
6971

7072
@Override

powertools-validation/src/main/java/software/amazon/lambda/powertools/validation/ValidationUtils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.io.IOException;
1717
import java.io.InputStream;
18+
import java.util.Collections;
1819
import java.util.Map;
1920
import java.util.Set;
2021
import java.util.concurrent.ConcurrentHashMap;
@@ -271,12 +272,12 @@ public static class ValidationErrors {
271272

272273
private final Set<ValidationMessage> validationErrors;
273274

274-
public ValidationErrors(Set<ValidationMessage> validationErrors) {
275+
private ValidationErrors(Set<ValidationMessage> validationErrors) {
275276
this.validationErrors = validationErrors;
276277
}
277278

278279
public Set<ValidationMessage> getValidationErrors() {
279-
return validationErrors;
280+
return Collections.unmodifiableSet(validationErrors);
280281
}
281282
}
282283
}

spotbugs-exclude.xml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<!-- This file specifies a spotbugs filter for excluding reports that
2+
should not be considered errors.
3+
The format of this file is documented at:
4+
https://spotbugs.readthedocs.io/en/latest/filter.html
5+
When possible, please specify the full names of the bug codes,
6+
using the pattern attribute, to make it clearer what reports are
7+
being suppressed. You can find a listing of codes at:
8+
https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html
9+
-->
10+
<FindBugsFilter>
11+
<!-- Internals of Log event for apache log4j-->
12+
<Match>
13+
<Bug pattern="EI_EXPOSE_REP"/>
14+
<Or>
15+
<And>
16+
<Class name="org.apache.logging.log4j.core.layout.LambdaJsonLayout$LogEventWithAdditionalFields"/>
17+
<Method name="getLogEvent"/>
18+
</And>
19+
<And>
20+
<Class name="org.apache.logging.log4j.core.layout.LambdaJsonLayout$LogEventWithAdditionalFields"/>
21+
<Method name="getAdditionalFields"/>
22+
</And>
23+
</Or>
24+
</Match>
25+
<Match>
26+
<Bug pattern="EI_EXPOSE_REP2"/>
27+
<Or>
28+
<And>
29+
<Class name="org.apache.logging.log4j.core.layout.LambdaJsonLayout$LogEventWithAdditionalFields"/>
30+
<Field name="logEvent"/>
31+
</And>
32+
<And>
33+
<Class name="org.apache.logging.log4j.core.layout.LambdaJsonLayout$LogEventWithAdditionalFields"/>
34+
<Field name="additionalFields"/>
35+
</And>
36+
<And>
37+
<Class name="software.amazon.lambda.powertools.sqs.internal.BatchContext"/>
38+
<Field name="client"/>
39+
</And>
40+
<And>
41+
<Class name="software.amazon.lambda.powertools.parameters.BaseProvider"/>
42+
<Field name="cacheManager"/>
43+
</And>
44+
<And>
45+
<Class name="software.amazon.lambda.powertools.parameters.transform.TransformationManager"/>
46+
<Field name="transformer"/>
47+
</And>
48+
</Or>
49+
</Match>
50+
<!--Functionally needed-->
51+
<Match>
52+
<Bug pattern="EI_EXPOSE_STATIC_REP2"/>
53+
<Or>
54+
<And>
55+
<Class name="software.amazon.lambda.powertools.logging.LoggingUtils"/>
56+
<Method name="defaultObjectMapper"/>
57+
</And>
58+
<And>
59+
<Class name="software.amazon.lambda.powertools.sqs.SqsUtils"/>
60+
<Method name="overrideSqsClient"/>
61+
</And>
62+
</Or>
63+
</Match>
64+
<Match>
65+
<Bug pattern="MS_EXPOSE_REP"/>
66+
<Or>
67+
<And>
68+
<Class name="software.amazon.lambda.powertools.logging.LoggingUtils"/>
69+
<Method name="objectMapper"/>
70+
</And>
71+
<And>
72+
<Class name="software.amazon.lambda.powertools.sqs.SqsUtils"/>
73+
<Method name="objectMapper"/>
74+
</And>
75+
<And>
76+
<Class name="software.amazon.lambda.powertools.parameters.ParamManager"/>
77+
<Method name="getCacheManager"/>
78+
</And>
79+
<And>
80+
<Class name="software.amazon.lambda.powertools.parameters.ParamManager"/>
81+
<Method name="getTransformationManager"/>
82+
</And>
83+
</Or>
84+
</Match>
85+
<!--False positive https://github.com/spotbugs/spotbugs/issues/1539-->
86+
<Match>
87+
<Bug pattern="DMI_RANDOM_USED_ONLY_ONCE"/>
88+
<Class name="software.amazon.lambda.powertools.logging.internal.LambdaLoggingAspect"/>
89+
<Method name="setLogLevelBasedOnSamplingRate"/>
90+
</Match>
91+
</FindBugsFilter>

0 commit comments

Comments
 (0)