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

java.net.URL.getUserInfo() and getHost() methods fail when username includes @

XMLWordPrintable

    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      Java 8 fails as described
      Java 11 fails as described
      Java 1.6/6 doesn't consider this a valid URL

      A DESCRIPTION OF THE PROBLEM :
      Create a URL that includes username and password where the username is an email address, basically including the @. When you call getUserInfo, it returns null. When you call getHost(), it returns an empty string. getFile() and getProtocol() work fine.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the included source

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      URL url = new URL("https://email@example.com:password@oracle.com/foobar");
      System.out.println("Info: " + url.getUserInfo()); // email@example.com:password
      System.out.println("Host: " + url.getHost()); // oracle.com
      System.out.println("File: " + url.getFile()); // foobar
      System.out.println("Prot: " + url.getProtocol()); // https

      ACTUAL -
      URL url = new URL("https://email@example.com:password@oracle.com/foobar");
      System.out.println("Info: " + url.getUserInfo()); // null -- failure
      System.out.println("Host: " + url.getHost()); // empty -- failure
      System.out.println("File: " + url.getFile()); // works
      System.out.println("Prot: " + url.getProtocol()); // works



      ---------- BEGIN SOURCE ----------
      import java.net.*;

      public class Test {
         public static void main(String args[]) throws Exception {
      URL url = new URL("https://email@example.com:password@oracle.com/foobar");
      System.out.println("Info: " + url.getUserInfo()); // null
      System.out.println("Host: " + url.getHost()); // empty
      System.out.println("File: " + url.getFile()); // works
      System.out.println("Prot: " + url.getProtocol()); // works
         }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: