Skip to content

Allow SDK to build on JDK 17 #3037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-c032289.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"category": "AWS SDK for Java v2",
"contributor": "",
"type": "feature",
"description": "Update SDK to be able to successfully build using JDK 17."
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,10 +345,20 @@
<module name="Regexp">
<property name="format" value="System\s*(\.|::)\s*(getenv|getProperty)"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Use SystemSetting instead of System.getenv and System.getProperty"/>
<property name="message" value="NEVER use System.getenv or System.getProperty. Create and use a
SystemSetting, instead."/>
<property name="ignoreComments" value="true"/>
</module>

<module name="Regexp">
<property name="format" value="SystemSetting\s*(\.|::)\s*getStringValueFromEnvironmentVariable"/>
<property name="illegalPattern" value="true"/>
<property name="message" value="Are you being naughty and not creating a SystemSetting? Don't you know that
your customers want both system properties AND environment variables? Are you REALLY sure you want to use
this and not support a system property?"/>
<property name="ignoreComments" value="true"/>
</module>
Comment on lines +348 to +360
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers: This was modified to really push people to use SystemSetting, because that's the only mechanism that supports environment variable mocking, now. We expect everyone to create new SystemSettings to support both properties and environment variables. If they really want to break that, then they can use the static SystemSetting.getStringValueFromEnvironmentVariable (long to be annoying to write), and they still have to add a checkstyle suppression to do it.


<!-- Checks that we don't implement AutoCloseable/Closeable -->
<module name="Regexp">
<property name="format" value="(class|interface).*(implements|extends).*[^\w](Closeable|AutoCloseable)[^\w]"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
<Class name="software.amazon.awssdk.protocols.json.internal.dom.JsonDomParser"/>
<Class name="software.amazon.awssdk.testutils.service.AwsIntegrationTestBase"/>
<Class name="software.amazon.awssdk.protocol.asserts.marshalling.XmlAsserts" />
<Class name="software.amazon.awssdk.testutils.FileUtils"/>
</Or>
<Bug pattern="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
</Match>
Expand Down Expand Up @@ -224,4 +225,9 @@
<Method name="create"/>
<Bug pattern="ISC_INSTANTIATE_STATIC_CLASS"/>
</Match>

<!-- This is very buggy https://github.com/spotbugs/spotbugs/issues/1539 -->
<Match>
<Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -31,7 +31,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.config.customization.UnderscoresInNameBehavior;
import software.amazon.awssdk.codegen.model.config.customization.ShareModelConfig;
Expand Down Expand Up @@ -139,7 +139,6 @@ public void test_GetFluentSetterMethodName_NoEnum() {
@Test
public void test_GetFluentSetterMethodName_NoEnum_WithList() {
when(serviceModel.getShapes()).thenReturn(mockShapeMap);
when(mockShapeMap.get(eq("MockShape"))).thenReturn(mockShape);
when(mockShapeMap.get(eq("MockStringShape"))).thenReturn(mockStringShape);

when(mockShape.getEnumValues()).thenReturn(null);
Expand All @@ -157,7 +156,6 @@ public void test_GetFluentSetterMethodName_NoEnum_WithList() {
@Test
public void test_GetFluentSetterMethodName_WithEnumShape_NoListOrMap() {
when(serviceModel.getShapes()).thenReturn(mockShapeMap);
when(mockShapeMap.get(any())).thenReturn(mockShape);
when(mockShape.getEnumValues()).thenReturn(new ArrayList<>());
when(mockShape.getType()).thenReturn("foo");

Expand All @@ -167,7 +165,6 @@ public void test_GetFluentSetterMethodName_WithEnumShape_NoListOrMap() {
@Test
public void test_GetFluentSetterMethodName_WithEnumShape_WithList() {
when(serviceModel.getShapes()).thenReturn(mockShapeMap);
when(mockShapeMap.get(eq("MockShape"))).thenReturn(mockShape);
when(mockShapeMap.get(eq("MockStringShape"))).thenReturn(mockStringShape);

when(mockShape.getEnumValues()).thenReturn(null);
Expand All @@ -182,13 +179,6 @@ public void test_GetFluentSetterMethodName_WithEnumShape_WithList() {
assertThat(strat.getFluentSetterMethodName("AwesomeMethod", mockParentShape, mockShape)).isEqualTo("awesomeMethodWithStrings");
}

@Test
public void test_GetFluentSetterMethodName_NoEum_WithMap() {
when(serviceModel.getShapes()).thenReturn(mockShapeMap);
when(mockShape.getEnumValues()).thenReturn(new ArrayList<>());

}

@Test
public void nonSharedModel_packageName() {
String serviceName = "foo";
Expand Down Expand Up @@ -259,8 +249,6 @@ public void modelNameShouldHavePascalCase() {
public void getServiceName_Uses_ServiceId() {
when(serviceModel.getMetadata()).thenReturn(serviceMetadata);
when(serviceMetadata.getServiceId()).thenReturn("Foo");
when(serviceMetadata.getServiceAbbreviation()).thenReturn("Abbr");
when(serviceMetadata.getServiceFullName()).thenReturn("Foo Service");

assertThat(strat.getServiceName()).isEqualTo("Foo");
}
Expand All @@ -269,8 +257,6 @@ public void getServiceName_Uses_ServiceId() {
public void getServiceName_ThrowsException_WhenServiceIdIsNull() {
when(serviceModel.getMetadata()).thenReturn(serviceMetadata);
when(serviceMetadata.getServiceId()).thenReturn(null);
when(serviceMetadata.getServiceAbbreviation()).thenReturn("Abbr");
when(serviceMetadata.getServiceFullName()).thenReturn("Foo Service");

strat.getServiceName();
}
Expand All @@ -279,8 +265,6 @@ public void getServiceName_ThrowsException_WhenServiceIdIsNull() {
public void getServiceName_ThrowsException_WhenServiceIdIsEmpty() {
when(serviceModel.getMetadata()).thenReturn(serviceMetadata);
when(serviceMetadata.getServiceId()).thenReturn("");
when(serviceMetadata.getServiceAbbreviation()).thenReturn("Abbr");
when(serviceMetadata.getServiceFullName()).thenReturn("Foo Service");

strat.getServiceName();
}
Expand All @@ -289,8 +273,6 @@ public void getServiceName_ThrowsException_WhenServiceIdIsEmpty() {
public void getServiceName_ThrowsException_WhenServiceIdHasWhiteSpace() {
when(serviceModel.getMetadata()).thenReturn(serviceMetadata);
when(serviceMetadata.getServiceId()).thenReturn(" ");
when(serviceMetadata.getServiceAbbreviation()).thenReturn("Abbr");
when(serviceMetadata.getServiceFullName()).thenReturn("Foo Service");

strat.getServiceName();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.signer.internal.chunkedencoding.AwsSignedChunkedEncodingInputStream;
import software.amazon.awssdk.authcrt.signer.internal.SigningConfigProvider;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.authcrt.signer.internal.SigningConfigProvider;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.crt.auth.signing.AwsSigningConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.authcrt.signer.internal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

Expand All @@ -34,7 +34,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.core.internal.chunked.AwsChunkedEncodingConfig;
import software.amazon.awssdk.auth.signer.internal.chunkedencoding.AwsSignedChunkedEncodingInputStream;
import software.amazon.awssdk.authcrt.signer.internal.chunkedencoding.AwsS3V4aChunkSigner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
import static software.amazon.awssdk.authcrt.signer.internal.SigningUtils.SIGNING_CLOCK;
import static software.amazon.awssdk.authcrt.signer.internal.SigningUtils.buildCredentials;
Expand All @@ -41,7 +41,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute;
import software.amazon.awssdk.core.internal.chunked.AwsChunkedEncodingConfig;
Expand Down Expand Up @@ -139,8 +139,6 @@ public void setup() throws Exception {
executionAttributes = buildBasicExecutionAttributes();
chunkedRequestSigningConfig = createChunkedRequestSigningConfig(executionAttributes);
chunkSigningConfig = createChunkSigningConfig(executionAttributes);
when(configProvider.createS3CrtSigningConfig(any())).thenReturn(chunkedRequestSigningConfig);
when(configProvider.createChunkedSigningConfig(any())).thenReturn(createChunkSigningConfig(buildBasicExecutionAttributes()));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.authcrt.signer.internal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

import java.net.URI;
Expand All @@ -27,7 +27,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute;
import software.amazon.awssdk.auth.signer.S3SignerExecutionAttribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static EnvironmentVariableCredentialsProvider create() {
protected Optional<String> loadSetting(SystemSetting setting) {
// CHECKSTYLE:OFF - Customers should be able to specify a credentials provider that only looks at the environment
// variables, but not the system properties. For that reason, we're only checking the environment variable here.
return Optional.ofNullable(System.getenv(setting.environmentVariable()));
return SystemSetting.getStringValueFromEnvironmentVariable(setting.environmentVariable());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewer: Non-Mockito change. This uses SystemSetting to support mocking.

// CHECKSTYLE:ON
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void reset() {
@Test
public void creationDoesntInvokeSupplier() {
LazyAwsCredentialsProvider.create(credentialsConstructor);
Mockito.verifyZeroInteractions(credentialsConstructor);
Mockito.verifyNoMoreInteractions(credentialsConstructor);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.auth.signer;

import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -138,7 +138,7 @@ public void test_sign_futureCancelled_propagatedToPublisher() {
AsyncRequestBody mockRequestBody = mock(AsyncRequestBody.class);
Subscription mockSubscription = mock(Subscription.class);
doAnswer((Answer<Void>) invocationOnMock -> {
Subscriber subscriber = invocationOnMock.getArgumentAt(0, Subscriber.class);
Subscriber subscriber = invocationOnMock.getArgument(0, Subscriber.class);
subscriber.onSubscribe(mockSubscription);
return null;
}).when(mockRequestBody).subscribe(any(Subscriber.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.auth.signer.internal;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

Expand All @@ -33,7 +33,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.core.internal.chunked.AwsChunkedEncodingConfig;
import software.amazon.awssdk.auth.signer.internal.chunkedencoding.AwsSignedChunkedEncodingInputStream;
import software.amazon.awssdk.auth.signer.internal.chunkedencoding.AwsS3V4ChunkSigner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Matchers.anyLong;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.awscore.client.builder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand All @@ -39,7 +39,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.auth.signer.Aws4Signer;
import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
Expand Down Expand Up @@ -84,7 +84,6 @@ public class DefaultAwsClientBuilderTest {
public void setup() {
when(defaultHttpClientBuilder.buildWithDefaults(any())).thenReturn(mock(SdkHttpClient.class));
when(defaultAsyncHttpClientFactory.buildWithDefaults(any())).thenReturn(mock(SdkAsyncHttpClient.class));
when(autoModeDiscovery.discover(any())).thenReturn(DefaultsMode.IN_REGION);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.awscore.client.builder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static software.amazon.awssdk.awscore.client.config.AwsAdvancedClientOption.ENABLE_DEFAULT_REGION_DETECTION;
Expand All @@ -29,7 +29,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
import software.amazon.awssdk.awscore.defaultsmode.DefaultsMode;
import software.amazon.awssdk.awscore.internal.defaultsmode.AutoDefaultsModeDiscovery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package software.amazon.awssdk.awscore.client.handler;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -29,7 +29,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.auth.signer.AwsSignerExecutionAttribute;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DefaultMetricCollection(String name, Map<SdkMetric<?>,
List<MetricRecord<?>>> metrics, List<MetricCollection> children) {
this.name = name;
this.metrics = new HashMap<>(metrics);
this.children = children != null ? Collections.unmodifiableList(new ArrayList<>(children)) : Collections.emptyList();
this.children = children != null ? new ArrayList<>(children) : Collections.emptyList();
this.creationTime = Instant.now();
}

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

@Override
public List<MetricCollection> children() {
return children;
return Collections.unmodifiableList(children);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private Boolean parseBooleanProperty(String propertyKey, String property) {
* Retrieve an unmodifiable view of all of the properties currently in this profile.
*/
public Map<String, String> properties() {
return properties;
return Collections.unmodifiableMap(properties);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still require wrapping the input list as unmodifiableMap in builder line number 193 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! I didn't see that (and neither did spotbugs).

}

@Override
Expand Down
Loading