You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "zzzk1 (via GitHub)" <gi...@apache.org> on 2025/01/22 15:54:32 UTC

[PR] [#4209] Chore replace hardcoded value with std definition [gravitino]

zzzk1 opened a new pull request, #6354:
URL: https://github.com/apache/gravitino/pull/6354

   <!--
   1. Title: [#<issue>] <type>(<scope>): <subject>
      Examples:
        - "[#123] feat(operator): support xxx"
        - "[#233] fix: check null before access result in xxx"
        - "[MINOR] refactor: fix typo in variable name"
        - "[MINOR] docs: fix typo in README"
        - "[#255] test: fix flaky test NameOfTheTest"
      Reference: https://www.conventionalcommits.org/en/v1.0.0/
   2. If the PR is unfinished, please mark this PR as draft.
   -->
   
   ### What changes were proposed in this pull request?
   Use standard definition lib value to replace the hardcoded value: UTF-8.
   ### Why are the changes needed?
   
   (Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, describe the bug.)
   
   Fix: #4209
   
   ### Does this PR introduce _any_ user-facing change?
   
   (Please list the user-facing changes introduced by your change, including
     1. Change in user-facing APIs.
     2. Addition or removal of property keys.)
   
   ### How was this patch tested?
   
   (Please test your changes, and provide instructions on how to test it:
     1. If you add a feature or fix a bug, add a test to cover your changes.
     2. If you fix a flaky test, repeat it for many times to prove it works.)
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "zzzk1 (via GitHub)" <gi...@apache.org>.
zzzk1 commented on code in PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#discussion_r1926292078


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   we can't do that, if we use:
    ```java
   try {
           return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), StandardCharsets.UTF_8);
         } catch (UnsupportedEncodingException e) {
           throw new IllegalCharsetNameException("UTF-8"); // won't happen.
         }
   ```
   
   the complier will report **Exception java.io.UnsupportedEncodingException is never thrown in the corresponding try block** like this:
   > <img width="870" alt="Screenshot 2025-01-23 at 10 53 59" src="https://github.com/user-attachments/assets/e40b00f8-7c10-4b68-8031-e9402f243ff7" />
   
   maybe we can use `Exception` replace `UnsupportedEncodingException`?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#discussion_r1926215533


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   That seems Ok, but I assume it was there for some reason for it originally, so it may not be best to remove it.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "zzzk1 (via GitHub)" <gi...@apache.org>.
zzzk1 commented on PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#issuecomment-2609889957

   > Can you please update the PR description like other PRs?
   
   yes


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#discussion_r1926215533


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   That seems Ok, but I assume it was there for some reason originally so may not be best to remove.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "zzzk1 (via GitHub)" <gi...@apache.org>.
zzzk1 commented on code in PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#discussion_r1926292357


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   > That seems Ok, but I assume it was there for some reason for it originally, so it may not be best to remove it.
   
   we can't do that, if we use:
    ```java
   try {
           return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), StandardCharsets.UTF_8);
         } catch (UnsupportedEncodingException e) {
           throw new IllegalCharsetNameException("UTF-8"); // won't happen.
         }
   ```
   
   the complier will report **Exception java.io.UnsupportedEncodingException is never thrown in the corresponding try block** like this:
   > <img width="870" alt="Screenshot 2025-01-23 at 10 53 59" src="https://github.com/user-attachments/assets/e40b00f8-7c10-4b68-8031-e9402f243ff7" />
   
   maybe we can use `Exception` replace `UnsupportedEncodingException`?



##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   we can't do that, if we use:
    ```java
   try {
           return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), StandardCharsets.UTF_8);
         } catch (UnsupportedEncodingException e) {
           throw new IllegalCharsetNameException("UTF-8"); // won't happen.
         }
   ```
   
   the complier will report **Exception java.io.UnsupportedEncodingException is never thrown in the corresponding try block** like this:
   > <img width="870" alt="Screenshot 2025-01-23 at 10 53 59" src="https://github.com/user-attachments/assets/e40b00f8-7c10-4b68-8031-e9402f243ff7" />
   
   maybe we can use `Exception` replace `UnsupportedEncodingException`?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "zzzk1 (via GitHub)" <gi...@apache.org>.
zzzk1 commented on code in PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#discussion_r1926141324


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   > Why did you remove this code?
   
   The String constructor used here does not declare that it throws an `UnsupportedEncodingException` because `StandardCharsets.UTF_8` guarantees that the encoding is supported. However, an `IndexOutOfBoundsException` could occur in this context.



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#issuecomment-2609799493

   Can you please update the PR description like other PRs?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#issuecomment-2608346548

   We use Spotless to ensure our code is consistently formatted. You'll need to run `./gradlew :server-common:spotlessApply` to correct the formatting to get the CI checks to pass.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean commented on code in PR #6354:
URL: https://github.com/apache/gravitino/pull/6354#discussion_r1926008430


##########
server-common/src/main/java/org/apache/gravitino/server/authentication/KerberosServerUtils.java:
##########
@@ -353,11 +354,7 @@ DER get(int... tags) {
     }
 
     String getAsString() {
-      try {
-        return new String(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining(), "UTF-8");
-      } catch (UnsupportedEncodingException e) {
-        throw new IllegalCharsetNameException("UTF-8"); // won't happen.
-      }

Review Comment:
   Why did you remove this code?



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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


Re: [PR] [#4209] chore replace hardcoded value with std definition [gravitino]

Posted by "justinmclean (via GitHub)" <gi...@apache.org>.
justinmclean merged PR #6354:
URL: https://github.com/apache/gravitino/pull/6354


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

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