Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8351411

java.net.URISyntaxException: Illegal character in query

    • 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

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: