File tree Expand file tree Collapse file tree 4 files changed +51
-1
lines changed
it/java/software/amazon/awssdk/services/s3
main/java/software/amazon/awssdk/services/s3/internal/endpoints
test/java/software/amazon/awssdk/services/s3 Expand file tree Collapse file tree 4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change
1
+ {
2
+ "category" : " Amazon S3" ,
3
+ "contributor" : " " ,
4
+ "type" : " bugfix" ,
5
+ "description" : " Fixed an issue that resulted in a NullPointerException when an invalid or global region was used on an S3 client. Fixes [#2885](https://github.com/aws/aws-sdk-java-v2/issues/2885)."
6
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License").
5
+ * You may not use this file except in compliance with the License.
6
+ * A copy of the License is located at
7
+ *
8
+ * http://aws.amazon.com/apache2.0
9
+ *
10
+ * or in the "license" file accompanying this file. This file is distributed
11
+ * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12
+ * express or implied. See the License for the specific language governing
13
+ * permissions and limitations under the License.
14
+ */
15
+
16
+ package software .amazon .awssdk .services .s3 ;
17
+
18
+ import org .junit .Test ;
19
+ import software .amazon .awssdk .regions .Region ;
20
+
21
+ public class ListBucketsIntegrationTest extends S3IntegrationTestBase {
22
+ @ Test
23
+ public void listBuckets_InGlobal_DoesNotThrowException () {
24
+ try (S3Client s3 = s3ClientBuilder ().region (Region .AWS_GLOBAL ).build ()) {
25
+ s3 .listBuckets ();
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change 26
26
import java .net .URI ;
27
27
import software .amazon .awssdk .annotations .SdkInternalApi ;
28
28
import software .amazon .awssdk .http .SdkHttpRequest ;
29
+ import software .amazon .awssdk .regions .PartitionMetadata ;
29
30
import software .amazon .awssdk .regions .RegionMetadata ;
30
31
import software .amazon .awssdk .services .s3 .S3Configuration ;
31
32
import software .amazon .awssdk .services .s3 .internal .BucketUtils ;
@@ -69,7 +70,10 @@ public ConfiguredS3SdkHttpRequest applyEndpointConfiguration(S3EndpointResolverC
69
70
private static URI resolveEndpoint (S3EndpointResolverContext context ) {
70
71
SdkHttpRequest request = context .request ();
71
72
String protocol = request .protocol ();
72
- String dnsSuffixWithoutTagConsideration = RegionMetadata .of (context .region ()).domain ();
73
+ RegionMetadata regionMetadata = RegionMetadata .of (context .region ());
74
+ String dnsSuffixWithoutTagConsideration = regionMetadata != null ?
75
+ regionMetadata .domain () :
76
+ PartitionMetadata .of (context .region ()).dnsSuffix ();
73
77
S3Configuration serviceConfiguration = context .serviceConfiguration ();
74
78
75
79
boolean useAccelerate = isAccelerateEnabled (serviceConfiguration ) && isAccelerateSupported (context .originalRequest ());
Original file line number Diff line number Diff line change 22
22
import software .amazon .awssdk .auth .credentials .AnonymousCredentialsProvider ;
23
23
import software .amazon .awssdk .core .exception .SdkClientException ;
24
24
import software .amazon .awssdk .regions .Region ;
25
+ import software .amazon .awssdk .services .s3 .model .HeadBucketRequest ;
25
26
import software .amazon .awssdk .services .s3 .presigner .S3Presigner ;
26
27
27
28
public class InvalidRegionTest {
@@ -47,6 +48,17 @@ public void invalidS3UtilitiesRegionAtRequestGivesHelpfulMessage() {
47
48
.hasMessageContaining ("us-west-2" );
48
49
}
49
50
51
+ @ Test
52
+ public void nonExistentRegionGivesHelpfulMessage () {
53
+ S3Client s3Client = S3Client .builder ()
54
+ .region (Region .of ("does-not-exist" ))
55
+ .credentialsProvider (AnonymousCredentialsProvider .create ())
56
+ .build ();
57
+ assertThatThrownBy (() -> s3Client .headBucket (HeadBucketRequest .builder ().bucket ("myBucket" ).build ()))
58
+ .isInstanceOf (SdkClientException .class )
59
+ .hasMessageContaining ("UnknownHostException" );
60
+ }
61
+
50
62
@ Test
51
63
public void invalidS3ArnRegionAtRequestGivesHelpfulMessage () {
52
64
S3Client client = S3Client .builder ()
You can’t perform that action at this time.
0 commit comments