[GitHub] [kafka] chia7712 commented on a change in pull request #10012: MINOR: Refactor return statement and log info

2021-02-08 Thread GitBox


chia7712 commented on a change in pull request #10012:
URL: https://github.com/apache/kafka/pull/10012#discussion_r572536164



##
File path: clients/src/main/java/org/apache/kafka/common/utils/Utils.java
##
@@ -1334,4 +1334,13 @@ public static long getDateTime(String timestamp) throws 
ParseException, IllegalA
 public static  Iterator covariantCast(Iterator 
iterator) {
 return (Iterator) iterator;
 }
+
+/**
+ * Checks if a string is null, empty or whitespace only.
+ * @param str a string to be checked
+ * @return true if the string is null, empty or whitespace only; 
otherwise, return false.
+ */
+public static boolean isBlank(String str) {

Review comment:
   How about applying this helper method to code base? 





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [kafka] chia7712 commented on a change in pull request #10012: MINOR: Refactor return statement and log info

2021-02-02 Thread GitBox


chia7712 commented on a change in pull request #10012:
URL: https://github.com/apache/kafka/pull/10012#discussion_r568422389



##
File path: 
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/unsecured/OAuthBearerUnsecuredValidatorCallbackHandler.java
##
@@ -170,33 +170,31 @@ private void handleCallback(OAuthBearerValidatorCallback 
callback) {
 .throwExceptionIfFailed();
 
OAuthBearerValidationUtils.validateTimeConsistency(unsecuredJwt).throwExceptionIfFailed();
 OAuthBearerValidationUtils.validateScope(unsecuredJwt, 
requiredScope).throwExceptionIfFailed();
-log.info("Successfully validated token with principal {}: {}", 
unsecuredJwt.principalName(),
-unsecuredJwt.claims().toString());
+if (log.isInfoEnabled()) {

Review comment:
   Is this condition check necessary? It is rare in code base.

##
File path: 
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/unsecured/OAuthBearerUnsecuredValidatorCallbackHandler.java
##
@@ -170,33 +170,31 @@ private void handleCallback(OAuthBearerValidatorCallback 
callback) {
 .throwExceptionIfFailed();
 
OAuthBearerValidationUtils.validateTimeConsistency(unsecuredJwt).throwExceptionIfFailed();
 OAuthBearerValidationUtils.validateScope(unsecuredJwt, 
requiredScope).throwExceptionIfFailed();
-log.info("Successfully validated token with principal {}: {}", 
unsecuredJwt.principalName(),
-unsecuredJwt.claims().toString());
+if (log.isInfoEnabled()) {
+log.info("Successfully validated token with principal {}: {}", 
unsecuredJwt.principalName(), unsecuredJwt.claims());
+}
 callback.token(unsecuredJwt);
 }
 
 private String principalClaimName() {
 String principalClaimNameValue = option(PRINCIPAL_CLAIM_NAME_OPTION);
-String principalClaimName = principalClaimNameValue != null && 
!principalClaimNameValue.trim().isEmpty()
+return principalClaimNameValue != null && 
!principalClaimNameValue.trim().isEmpty()

Review comment:
   How about adding a helper method to check both "null" and "empty"?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org




[GitHub] [kafka] chia7712 commented on a change in pull request #10012: MINOR: Refactor return statement and log info

2021-02-02 Thread GitBox


chia7712 commented on a change in pull request #10012:
URL: https://github.com/apache/kafka/pull/10012#discussion_r568422389



##
File path: 
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/unsecured/OAuthBearerUnsecuredValidatorCallbackHandler.java
##
@@ -170,33 +170,31 @@ private void handleCallback(OAuthBearerValidatorCallback 
callback) {
 .throwExceptionIfFailed();
 
OAuthBearerValidationUtils.validateTimeConsistency(unsecuredJwt).throwExceptionIfFailed();
 OAuthBearerValidationUtils.validateScope(unsecuredJwt, 
requiredScope).throwExceptionIfFailed();
-log.info("Successfully validated token with principal {}: {}", 
unsecuredJwt.principalName(),
-unsecuredJwt.claims().toString());
+if (log.isInfoEnabled()) {

Review comment:
   Is this condition check necessary? It is rare in code base.

##
File path: 
clients/src/main/java/org/apache/kafka/common/security/oauthbearer/internals/unsecured/OAuthBearerUnsecuredValidatorCallbackHandler.java
##
@@ -170,33 +170,31 @@ private void handleCallback(OAuthBearerValidatorCallback 
callback) {
 .throwExceptionIfFailed();
 
OAuthBearerValidationUtils.validateTimeConsistency(unsecuredJwt).throwExceptionIfFailed();
 OAuthBearerValidationUtils.validateScope(unsecuredJwt, 
requiredScope).throwExceptionIfFailed();
-log.info("Successfully validated token with principal {}: {}", 
unsecuredJwt.principalName(),
-unsecuredJwt.claims().toString());
+if (log.isInfoEnabled()) {
+log.info("Successfully validated token with principal {}: {}", 
unsecuredJwt.principalName(), unsecuredJwt.claims());
+}
 callback.token(unsecuredJwt);
 }
 
 private String principalClaimName() {
 String principalClaimNameValue = option(PRINCIPAL_CLAIM_NAME_OPTION);
-String principalClaimName = principalClaimNameValue != null && 
!principalClaimNameValue.trim().isEmpty()
+return principalClaimNameValue != null && 
!principalClaimNameValue.trim().isEmpty()

Review comment:
   How about adding a helper method to check both "null" and "empty"?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org