-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
25
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
MacOS - 15.3.1 (24D70), JDK 21
A DESCRIPTION OF THE PROBLEM :
Using URL to retrieve the host, query string and path of from url string is deprecated in jdk 21. Replacing URL with URI throws java.net.URISyntaxException: Illegal character in query error.
In jdk 11
URL url = new URL(urlStr) -> url.getHost(), etc works properly.
URI uri = new URI(urlStr) -> produces java.net.URISyntaxException: Illegal character in query error
Tried to encode the url with utf-8, but it doesn't work
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
urlStr = "https://bugs.openjdk.org/0800.html?mpid=1393c40c-cf49-4fa6-b814-b38561c06829&mode={mode}&app_version={appVersion} "
private static String getPartnerPublicUrl(String urlStr) {
try {
// URL url = new URL(urlStr);
URI uri = new URI(urlStr);
String publicDomain = url.getHost();
String urlPrefix = urlStr.startsWith("https://") ? "https://" : (urlStr.startsWith("http://") ? "http://" : "");
return urlPrefix + publicDomain;
} catch (Exception e) {
log.error("Error getting partner public url", e);
return "";
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
https://bugs.openjdk.org
ACTUAL -
java.net.URISyntaxException: Illegal character in query
MacOS - 15.3.1 (24D70), JDK 21
A DESCRIPTION OF THE PROBLEM :
Using URL to retrieve the host, query string and path of from url string is deprecated in jdk 21. Replacing URL with URI throws java.net.URISyntaxException: Illegal character in query error.
In jdk 11
URL url = new URL(urlStr) -> url.getHost(), etc works properly.
URI uri = new URI(urlStr) -> produces java.net.URISyntaxException: Illegal character in query error
Tried to encode the url with utf-8, but it doesn't work
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
urlStr = "https://bugs.openjdk.org/0800.html?mpid=1393c40c-cf49-4fa6-b814-b38561c06829&mode={mode}&app_version={appVersion} "
private static String getPartnerPublicUrl(String urlStr) {
try {
// URL url = new URL(urlStr);
URI uri = new URI(urlStr);
String publicDomain = url.getHost();
String urlPrefix = urlStr.startsWith("https://") ? "https://" : (urlStr.startsWith("http://") ? "http://" : "");
return urlPrefix + publicDomain;
} catch (Exception e) {
log.error("Error getting partner public url", e);
return "";
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
https://bugs.openjdk.org
ACTUAL -
java.net.URISyntaxException: Illegal character in query