Skip to content

Commit 0227012

Browse files
committed
Fixed some findbugs issues.
1 parent 9c3c07c commit 0227012

File tree

10 files changed

+40
-12
lines changed

10 files changed

+40
-12
lines changed

build-tools/src/main/resources/software/amazon/awssdk/spotbugs-suppressions.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
<Class name="software.amazon.awssdk.protocols.json.internal.dom.JsonDomParser"/>
168168
<Class name="software.amazon.awssdk.testutils.service.AwsIntegrationTestBase"/>
169169
<Class name="software.amazon.awssdk.protocol.asserts.marshalling.XmlAsserts" />
170+
<Class name="software.amazon.awssdk.testutils.FileUtils"/>
170171
</Or>
171172
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
172173
</Match>
@@ -224,4 +225,9 @@
224225
<Method name="create"/>
225226
<Bug pattern="ISC_INSTANTIATE_STATIC_CLASS"/>
226227
</Match>
228+
229+
<!-- This is very buggy https://github.com/spotbugs/spotbugs/issues/1539 -->
230+
<Match>
231+
<Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
232+
</Match>
227233
</FindBugsFilter>

core/metrics-spi/src/main/java/software/amazon/awssdk/metrics/internal/DefaultMetricCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public DefaultMetricCollection(String name, Map<SdkMetric<?>,
4141
List<MetricRecord<?>>> metrics, List<MetricCollection> children) {
4242
this.name = name;
4343
this.metrics = new HashMap<>(metrics);
44-
this.children = children != null ? Collections.unmodifiableList(new ArrayList<>(children)) : Collections.emptyList();
44+
this.children = children != null ? new ArrayList<>(children) : Collections.emptyList();
4545
this.creationTime = Instant.now();
4646
}
4747

@@ -65,7 +65,7 @@ public <T> List<T> metricValues(SdkMetric<T> metric) {
6565

6666
@Override
6767
public List<MetricCollection> children() {
68-
return children;
68+
return Collections.unmodifiableList(children);
6969
}
7070

7171
@Override

core/profiles/src/main/java/software/amazon/awssdk/profiles/Profile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private Boolean parseBooleanProperty(String propertyKey, String property) {
108108
* Retrieve an unmodifiable view of all of the properties currently in this profile.
109109
*/
110110
public Map<String, String> properties() {
111-
return properties;
111+
return Collections.unmodifiableMap(properties);
112112
}
113113

114114
@Override

core/profiles/src/main/java/software/amazon/awssdk/profiles/ProfileFile.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public final class ProfileFile {
5959
private ProfileFile(Map<String, Map<String, String>> rawProfiles) {
6060
Validate.paramNotNull(rawProfiles, "rawProfiles");
6161

62-
this.profiles = Collections.unmodifiableMap(convertToProfilesMap(rawProfiles));
62+
this.profiles = convertToProfilesMap(rawProfiles);
6363
}
6464

6565
/**
@@ -107,7 +107,7 @@ public Optional<Profile> profile(String profileName) {
107107
* @return An unmodifiable collection of the profiles in this file, keyed by profile name.
108108
*/
109109
public Map<String, Profile> profiles() {
110-
return profiles;
110+
return Collections.unmodifiableMap(profiles);
111111
}
112112

113113
@Override

core/sdk-core/src/test/java/software/amazon/awssdk/core/http/InterruptFlagAlwaysClearsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class InterruptFlagAlwaysClearsTest {
6262
@Mock
6363
private HttpResponseHandler<SdkResponse> responseHandler;
6464

65-
@Mock
65+
@Mock(lenient = true)
6666
private HttpResponseHandler<SdkServiceException> errorResponseHandler;
6767

6868
@BeforeClass

http-clients/netty-nio-client/src/test/java/software/amazon/awssdk/http/nio/netty/internal/FutureCancelHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package software.amazon.awssdk.http.nio.netty.internal;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.mockito.Matchers.any;
19+
import static org.mockito.ArgumentMatchers.any;
2020
import static org.mockito.Mockito.never;
2121
import static org.mockito.Mockito.verify;
2222
import static org.mockito.Mockito.when;

pom.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<unitils.version>3.4.6</unitils.version>
107107
<xmlunit.version>1.3</xmlunit.version>
108108
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
109-
<spotbugs.version>4.5.3.0</spotbugs.version>
109+
<spotbugs.version>4.2.3</spotbugs.version>
110110
<netty-reactive-streams-http.version>2.0.5</netty-reactive-streams-http.version>
111111
<javapoet.verion>1.13.0</javapoet.verion>
112112
<org.eclipse.jdt.version>3.10.0</org.eclipse.jdt.version>
@@ -228,8 +228,7 @@
228228
<artifactId>maven-surefire-plugin</artifactId>
229229
<version>${maven.surefire.version}</version>
230230
<configuration>
231-
<!-- Blockhound doesn't support Java 13+ without flags: https://github.com/reactor/BlockHound/issues/33 -->
232-
<argLine>${argLine} -XX:+AllowRedefinitionToAddDeleteMethods</argLine>
231+
<argLine>${argLine}</argLine>
233232
<excludes>
234233
<exclude>**/*StabilityTest.java</exclude>
235234
<exclude>**/*StabilityTests.java</exclude>
@@ -657,6 +656,17 @@
657656
</properties>
658657
</profile>
659658

659+
<profile>
660+
<id>jdk-13-plus</id>
661+
<activation>
662+
<jdk>[13,)</jdk>
663+
</activation>
664+
<properties>
665+
<!-- Blockhound doesn't support Java 13+ without flags: https://github.com/reactor/BlockHound/issues/33 -->
666+
<argLine>-XX:+AllowRedefinitionToAddDeleteMethods</argLine>
667+
</properties>
668+
</profile>
669+
660670
<profile>
661671
<id>quick</id>
662672
<properties>

test/test-utils/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,16 @@
112112
<scope>test</scope>
113113
</dependency>
114114
</dependencies>
115+
116+
<build>
117+
<plugins>
118+
<plugin>
119+
<groupId>com.github.spotbugs</groupId>
120+
<artifactId>spotbugs-maven-plugin</artifactId>
121+
<configuration>
122+
<skip>true</skip>
123+
</configuration>
124+
</plugin>
125+
</plugins>
126+
</build>
115127
</project>

utils/src/main/java/software/amazon/awssdk/utils/ReflectionMethodInvoker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private Method getTargetMethod() throws NoSuchMethodException {
117117
try {
118118
targetMethod = clazz.getMethod(methodName, parameterTypes);
119119
return targetMethod;
120-
} catch (NullPointerException e) {
120+
} catch (RuntimeException e) {
121121
throw new RuntimeException(createInvocationErrorMessage(), e);
122122
}
123123
}

utils/src/main/java/software/amazon/awssdk/utils/async/FlatteningSubscriber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void onNext(Iterable<U> nextItems) {
107107
Validate.notNull(nextItems, "Collections flattened by the flattening subscriber must not contain null.");
108108
allItems.add(item);
109109
});
110-
} catch (NullPointerException e) {
110+
} catch (RuntimeException e) {
111111
upstreamSubscription.cancel();
112112
onError(e);
113113
throw e;

0 commit comments

Comments
 (0)