This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 03f0e41a29 [#8433] fix(common): Fix a JDK compatibility problem in
URLEncoder (#8436)
03f0e41a29 is described below
commit 03f0e41a298c12d5923f311e3a5e038f390776e6
Author: Mini Yu <[email protected]>
AuthorDate: Thu Sep 4 19:50:34 2025 +0800
[#8433] fix(common): Fix a JDK compatibility problem in URLEncoder (#8436)
### What changes were proposed in this pull request?
Replace method encode(String, Charset) with encode(String, String)
### Why are the changes needed?
Method singature encode(String, Charset) is not supported in JDK8
Fix: #8433
### Does this PR introduce _any_ user-facing change?
N/A.
### How was this patch tested?
Existing tests.
---
.../src/main/java/org/apache/gravitino/rest/RESTUtils.java | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
b/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
index 1a268de82f..8b95669cee 100644
--- a/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
+++ b/common/src/main/java/org/apache/gravitino/rest/RESTUtils.java
@@ -24,12 +24,14 @@ import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.io.UncheckedIOException;
+import java.io.UnsupportedEncodingException;
import java.net.ServerSocket;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.Random;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
/**
* Referred from Apache Iceberg's RESTUtil implementation
@@ -100,7 +102,11 @@ public class RESTUtils {
*/
public static String encodeString(String toEncode) {
Preconditions.checkArgument(toEncode != null, "Invalid string to encode:
null");
- return URLEncoder.encode(toEncode, StandardCharsets.UTF_8);
+ try {
+ return URLEncoder.encode(toEncode, StandardCharsets.UTF_8.name());
+ } catch (UnsupportedEncodingException e) {
+ throw new GravitinoRuntimeException("Failed to encode string: %s",
toEncode);
+ }
}
/**
@@ -113,7 +119,11 @@ public class RESTUtils {
*/
public static String decodeString(String encoded) {
Preconditions.checkArgument(encoded != null, "Invalid string to decode:
null");
- return URLDecoder.decode(encoded, StandardCharsets.UTF_8);
+ try {
+ return URLDecoder.decode(encoded, StandardCharsets.UTF_8.name());
+ } catch (UnsupportedEncodingException e) {
+ throw new GravitinoRuntimeException("Failed to decode string: %s",
encoded);
+ }
}
/**