Skip to content
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

connectionString() method should throw IllegalArgurmentException #7121

Merged
Merged
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -239,25 +239,29 @@ public ConfigurationClientBuilder endpoint(String endpoint) {
* @param connectionString Connection string in the format "endpoint={endpoint_value};id={id_value};
* secret={secret_value}"
* @return The updated ConfigurationClientBuilder object.
* @throws NullPointerException If {@code credential} is {@code null}.
* @throws NullPointerException If {@code connectionString} is {@code null}.
* @throws IllegalArgumentException if {@code connectionString} is an empty string. Or the secret is invalid and
Copy link
Member

Choose a reason for hiding this comment

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

No change required in this PR.

Do our Checkstyle rules need to be updated to catch this missing case? It looks like the IllegalArgumentException has been getting thrown for a while but never documented, we have a Checkstyle rule that should failed PR validation due to this.

Copy link
Member Author

Choose a reason for hiding this comment

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

created an issue to investigate it: #7147

* cannot instantiate HMAC-SHA256 MAC algorithm.
*/
public ConfigurationClientBuilder connectionString(String connectionString) {
Objects.requireNonNull(connectionString);
Objects.requireNonNull(connectionString, "'connectionString' cannot be null.");

if (CoreUtils.isNullOrEmpty(connectionString)) {
Copy link
Member

Choose a reason for hiding this comment

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

You can replace this with connectionString.isEmpty(). No need to do another null check in CoreUtils.

throw logger.logExceptionAsError(
new IllegalArgumentException("'connectionString' cannot be an empty string."));
}

try {
this.credential = new ConfigurationClientCredentials(connectionString);
} catch (InvalidKeyException err) {
throw logger.logExceptionAsError(new IllegalArgumentException(
"The secret is invalid and cannot instantiate the HMAC-SHA256 algorithm.", err));
"The secret is invalid and cannot instantiate the HMAC-SHA256 algorithm.", err));
} catch (NoSuchAlgorithmException err) {
throw logger.logExceptionAsError(
new IllegalArgumentException("HMAC-SHA256 MAC algorithm cannot be instantiated.", err));
}

this.endpoint = credential.getBaseUri();

// Clear TokenCredential in favor of connection string credential
this.tokenCredential = null;
return this;
}

Expand All @@ -272,9 +276,6 @@ public ConfigurationClientBuilder credential(TokenCredential tokenCredential) {
// token credential can not be null value
Objects.requireNonNull(tokenCredential);
this.tokenCredential = tokenCredential;

// Clear connection string based credential in favor of TokenCredential
this.credential = null;
return this;
}

Expand Down