-
Notifications
You must be signed in to change notification settings - Fork 912
Better arn parsing #6163
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
base: master
Are you sure you want to change the base?
Better arn parsing #6163
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just need a a changelog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to update account ID code path to use this new method?
* @param arn A string containing an ARN to parse. | ||
* @return An {@link Optional} containing the parsed {@link Arn} if valid, or empty if invalid. | ||
*/ | ||
public static Optional<Arn> tryFromString(String arn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It contains a lot of duplicate code. Can we extract common code?
One idea is to create a helper method that takes a boolean for throwing behavior private static Optional<Arn> parseArn(String arn, boolean throwOnError) {...}
public void tryFromString_InvalidArns_ShouldThrowExceptions(String testName, String arnString) { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
Arn.tryFromString(arnString); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I thought it would no longer throw exception, did I miss anything?
Motivation and Context
Addresses #6108 .
Currently the SDK uses exceptions as control flow for arn parsing. This is an anti pattern in Java and can cause performance overhead.
Modifications
This PR adds another arn parsing method
tryFromString(arn)
that would return an Optional of Arn when the arn is valid, and an empty when it is invalid - this avoids the hot path of throwing exceptions as control flow.Testing
Unit tests: