Skip to content

Commit

Permalink
Merge branch 'arn-parse-exception-message' of https://github.com/belu…
Browse files Browse the repository at this point in the history
…gabehr/aws-sdk-java-v2 into arn-parse-exception-message
  • Loading branch information
belugabehr committed Sep 20, 2023
2 parents 52d8720 + df87ae5 commit 246e5f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/arns/src/main/java/software/amazon/awssdk/arns/Arn.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ public static Arn parseString(String arn) {
if (partitionColonIndex < 0) {
throw new IllegalArgumentException("Malformed ARN. No AWS partition specified: " + arn);
}
String partition = arn.substring(arnColonIndex + 1, partitionColonIndex);

String partition = arn.substring(arnColonIndex + 1, partitionColonIndex);
int serviceColonIndex = arn.indexOf(':', partitionColonIndex + 1);
if (serviceColonIndex < 0) {
throw new IllegalArgumentException("Malformed ARN. No service specified: " + arn);
}
String service = arn.substring(partitionColonIndex + 1, serviceColonIndex);

String service = arn.substring(partitionColonIndex + 1, serviceColonIndex);
int regionColonIndex = arn.indexOf(':', serviceColonIndex + 1);
if (regionColonIndex < 0) {
throw new IllegalArgumentException("Malformed ARN. No AWS region specified: " + arn);
Expand All @@ -182,6 +182,7 @@ public static Arn parseString(String arn) {
if (accountColonIndex < 0) {
throw new IllegalArgumentException("Malformed ARN. No AWS account specified: " + arn);
}

String accountId = arn.substring(regionColonIndex + 1, accountColonIndex);

String resource = arn.substring(accountColonIndex + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void arnWithoutPartition_ThrowsIllegalArgumentException() {
@Test
public void arnWithoutService_ThrowsIllegalArgumentException() {
String arnString = "arn:aws::us-east-1:12345678910:myresource";
assertThatThrownBy(() -> Arn.fromString(arnString)).hasMessageContaining("service must not be blank or empty");
assertThatThrownBy(() -> Arn.fromString(arnString)).getCause().hasMessageContaining("service must not be blank or empty");
}

@Test
Expand Down

0 comments on commit 246e5f4

Please sign in to comment.