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

Changes for javadoc and logger #4552

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -118,13 +118,11 @@ public String computeHmac256(final String stringToSign) {
byte[] utf8Bytes = stringToSign.getBytes(StandardCharsets.UTF_8);
return Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes));
} catch (final NoSuchAlgorithmException e) {
String errorMsg = "There is no such algorithm. Error Details: " + e.getMessage();
logger.warning(errorMsg);
throw new RuntimeException(errorMsg);
logger.logAndThrow(new RuntimeException("There is no such algorithm. Error Details: " + e.getMessage()));
Copy link
Member

Choose a reason for hiding this comment

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

Change this to IllegalStateException as it better aligns with the spec.

return null;
} catch (InvalidKeyException e) {
String errorMsg = "Please double check the account key. Error details: " + e.getMessage();
logger.warning(errorMsg);
throw new RuntimeException(errorMsg);
logger.logAndThrow(new RuntimeException("Please double check the account key. Error details: " + e.getMessage()));
Copy link
Member

Choose a reason for hiding this comment

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

Change this to IllegalStateException as it better aligns with the spec.

return null;
}
}

Expand Down Expand Up @@ -236,8 +234,8 @@ private String computeHMACSHA256(String stringToSign) {
String signature = Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes));
return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature);
} catch (NoSuchAlgorithmException | InvalidKeyException ex) {
logger.warning(ex.getMessage());
throw new Error(ex);
logger.logAndThrow(new RuntimeException(ex.getMessage()));
Copy link
Member

Choose a reason for hiding this comment

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

Pass in the exception itself into the constructor and change this to use IllegalStateException as that better aligns with the spec.

return null;
}
}
}
14 changes: 0 additions & 14 deletions sdk/storage/azure-storage-queue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
<artifactId>azure-core</artifactId>
<version>1.0.0-preview.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>com.azure</groupId>
Expand All @@ -59,20 +55,10 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* SharedKey credential policy that is put into a header to authorize requests.
*/
public final class SharedKeyCredential {
private static final ClientLogger LOGGER = new ClientLogger(SharedKeyCredential.class);
private final ClientLogger logger = new ClientLogger(SharedKeyCredential.class);
private static final String AUTHORIZATION_HEADER_FORMAT = "SharedKey %s:%s";

// Pieces of the connection string that are needed.
Expand Down Expand Up @@ -101,8 +101,10 @@ public String generateAuthorizationHeader(URL requestURL, String httpMethod, Map
* @param stringToSign The UTF-8-encoded string to sign.
* @return A {@code String} that contains the HMAC-SHA256-encoded signature.
* @throws RuntimeException for one of the following cases:
* - If the HMAC-SHA256 signature for {@code sharedKeyCredentials} fails to generate.
* - If the an invalid key has been given to the client.
* <ul>
* <li>If the HMAC-SHA256 signature for {@code sharedKeyCredentials} fails to generate.</li>
* <li>If the an invalid key has been given to the client.</li>
* </ul>
*/
public String computeHmac256(final String stringToSign) {
try {
Expand All @@ -116,11 +118,11 @@ public String computeHmac256(final String stringToSign) {
byte[] utf8Bytes = stringToSign.getBytes(StandardCharsets.UTF_8);
return Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes));
} catch (final NoSuchAlgorithmException e) {
LOGGER.error(e.getMessage());
throw new RuntimeException(e);
logger.logAndThrow(new RuntimeException(e));
Copy link
Member

Choose a reason for hiding this comment

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

Change this to IllegalStateException as it better aligns with the spec.

return null;
} catch (InvalidKeyException e) {
LOGGER.error("Please double check the account key. Error details: " + e.getMessage());
throw new RuntimeException("Please double check the account key. Error details: " + e.getMessage());
logger.logAndThrow(new RuntimeException("Please double check the account key. Error details: " + e.getMessage()));
Copy link
Member

Choose a reason for hiding this comment

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

Change this to IllegalStateException as it better aligns with the spec.

return null;
}
}

Expand Down Expand Up @@ -232,8 +234,8 @@ private String computeHMACSHA256(String stringToSign) {
String signature = Base64.getEncoder().encodeToString(hmacSha256.doFinal(utf8Bytes));
return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature);
} catch (NoSuchAlgorithmException | InvalidKeyException ex) {
LOGGER.error(ex.getMessage());
throw new Error(ex);
logger.logAndThrow(new RuntimeException(ex.getMessage()));
Copy link
Member

Choose a reason for hiding this comment

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

Pass in the exception itself into the constructor and change this to use IllegalStateException as that better aligns with the spec.

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public RequestRetryOptions() {
*
* <p>For more samples, please see the <a href="https://github.com/Azure/azure-storage-java/blob/master/src/test/java/com/microsoft/azure/storage/Samples.java">samples file</a></p>
* @throws IllegalArgumentException If one of the following case exists:
* <ul>
* <li> There is only one null value for retryDelay and maxRetryDelay.<li/>
* <li> Unrecognized retry policy type.<li/>
* </ul>
* <ul>
* <li> There is only one null value for retryDelay and maxRetryDelay.<li/>
* <li> Unrecognized retry policy type.<li/>
* </ul>
*/
public RequestRetryOptions(RetryPolicyType retryPolicyType, Integer maxTries, Integer tryTimeout,
Long retryDelayInMs, Long maxRetryDelayInMs, String secondaryHost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* @see SASTokenCredential
*/
public final class QueueAsyncClient {
private static final ClientLogger LOGGER = new ClientLogger(QueueAsyncClient.class);
private final ClientLogger logger = new ClientLogger(QueueAsyncClient.class);
private final AzureQueueStorageImpl client;
private final String queueName;

Expand Down Expand Up @@ -94,8 +94,8 @@ public URL getQueueUrl() {
try {
return new URL(client.getUrl());
} catch (MalformedURLException ex) {
LOGGER.error("Queue URL is malformed");
throw new RuntimeException("Queue URL is malformed");
logger.logAndThrow(new RuntimeException("Queue URL is malformed"));
Copy link
Member

Choose a reason for hiding this comment

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

Change this to IllegalStateException as it better aligns with the spec.

return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
* @see SharedKeyCredential
*/
public final class QueueClientBuilder {
private static final ClientLogger LOGGER = new ClientLogger(QueueClientBuilder.class);
private final ClientLogger logger = new ClientLogger(QueueClientBuilder.class);
private static final String ACCOUNT_NAME = "accountname";
private final List<HttpPipelinePolicy> policies;

Expand Down Expand Up @@ -138,8 +138,8 @@ public QueueAsyncClient buildAsyncClient() {
Objects.requireNonNull(queueName);

if (sasTokenCredential == null && sharedKeyCredential == null) {
LOGGER.error("Credentials are required for authorization");
throw new IllegalArgumentException("Credentials are required for authorization");
logger.logAndThrow(new IllegalArgumentException("Credentials are required for authorization"));
Copy link
Member

Choose a reason for hiding this comment

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

Change this to IllegalStateException as it better aligns with the spec.

return null;
}

if (pipeline != null) {
Expand Down Expand Up @@ -205,8 +205,8 @@ public QueueClientBuilder endpoint(String endpoint) {
this.sasTokenCredential = credential;
}
} catch (MalformedURLException ex) {
LOGGER.error("The Azure Storage Queue endpoint url is malformed. Endpoint: " + endpoint);
throw new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed. Endpoint: " + endpoint);
logger.logAndThrow(new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed. Endpoint: " + endpoint));
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Don't need to return null here, only use that when the code analyzer thinks there is no return case when one is needed.

}

return this;
Expand Down Expand Up @@ -273,10 +273,8 @@ private void getEndPointFromConnectionString(String connectionString) {
try {
this.endpoint = new URL(String.format("https://%s.queue.core.windows.net", accountName));
} catch (MalformedURLException e) {
LOGGER.error("There is no valid account for the connection string. "
+ "Connection String: %s", connectionString);
throw new IllegalArgumentException(String.format("There is no valid account for the connection string. "
+ "Connection String: %s", connectionString));
logger.logAndThrow(new IllegalArgumentException(String.format("There is no valid account for the connection string. "
+ "Connection String: %s", connectionString)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @see SASTokenCredential
*/
public final class QueueServiceAsyncClient {
private static final ClientLogger LOGGER = new ClientLogger(QueueServiceAsyncClient.class);
private final ClientLogger logger = new ClientLogger(QueueServiceAsyncClient.class);
private final AzureQueueStorageImpl client;

/**
Expand All @@ -71,8 +71,8 @@ public URL getQueueServiceUrl() {
try {
return new URL(client.getUrl());
} catch (MalformedURLException ex) {
LOGGER.error("Queue Service URL is malformed");
throw new RuntimeException("Storage account URL is malformed");
logger.logAndThrow(new RuntimeException("Storage account URL is malformed"));
Copy link
Member

Choose a reason for hiding this comment

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

Change this IllegalStateException to better align with the spec.

return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
* @see SharedKeyCredential
*/
public final class QueueServiceClientBuilder {
private static final ClientLogger LOGGER = new ClientLogger(QueueServiceClientBuilder.class);
private final ClientLogger logger = new ClientLogger(QueueServiceClientBuilder.class);
private static final String ACCOUNT_NAME = "accountname";
private final List<HttpPipelinePolicy> policies;

Expand Down Expand Up @@ -112,8 +112,8 @@ public QueueServiceAsyncClient buildAsyncClient() {
Objects.requireNonNull(endpoint);

if (sasTokenCredential == null && sharedKeyCredential == null) {
LOGGER.error("Credentials are required for authorization");
throw new IllegalArgumentException("Credentials are required for authorization");
logger.logAndThrow(new IllegalArgumentException("Credentials are required for authorization"));
Copy link
Member

Choose a reason for hiding this comment

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

Change this IllegalStateException to better align with the spec.

return null;
}

if (pipeline != null) {
Expand Down Expand Up @@ -189,8 +189,8 @@ public QueueServiceClientBuilder endpoint(String endpoint) {
this.sasTokenCredential = credential;
}
} catch (MalformedURLException ex) {
LOGGER.error("The Azure Storage Queue endpoint url is malformed.");
throw new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed.");
logger.logAndThrow(new IllegalArgumentException("The Azure Storage Queue endpoint url is malformed."));
return null;
}

return this;
Expand Down Expand Up @@ -245,10 +245,8 @@ private void getEndPointFromConnectionString(String connectionString) {
try {
this.endpoint = new URL(String.format("https://%s.queue.core.windows.net", accountName));
} catch (MalformedURLException e) {
LOGGER.error("There is no valid account for the connection string. "
+ "Connection String: %s", connectionString);
throw new IllegalArgumentException(String.format("There is no valid account for the connection string. "
+ "Connection String: %s", connectionString));
logger.logAndThrow(new IllegalArgumentException(String.format("There is no valid account for the connection string. "
Copy link
Member

Choose a reason for hiding this comment

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

Change this IllegalStateException to better align with the spec.

+ "Connection String: %s", connectionString)));
}
}

Expand Down