-
Notifications
You must be signed in to change notification settings - Fork 2k
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
mssfang
merged 4 commits into
Azure:master
from
mssfang:throw-illegal-arg-exception-in-java-doc
Jan 6, 2020
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* cannot instantiate HMAC-SHA256 MAC algorithm. | ||
alzimmermsft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public ConfigurationClientBuilder connectionString(String connectionString) { | ||
Objects.requireNonNull(connectionString); | ||
Objects.requireNonNull(connectionString, "'connectionString' cannot be null."); | ||
|
||
if (CoreUtils.isNullOrEmpty(connectionString)) { | ||
conniey marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
alzimmermsft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} 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; | ||
} | ||
|
||
|
@@ -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; | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.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.
created an issue to investigate it: #7147