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

java.net.URLStreamHandler.parseURL() works wrong with userInfo field

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.5



      Name: dfC67450 Date: 08/26/99



      java.net.URL.getUserInfo() returns null if userInfo is short enough.
      Source for URLStreamHandler.parseURL contains lines:

                  host = authority = spec.substring(start, i);
                  int ind = authority.indexOf('@', start);

      Second line should be:

                  int ind = authority.indexOf('@');

      to work correctly.

      Here is the test demonstrating the bug:
      -----------------URLTest.java------------------------
      import java.net.*;
      import java.io.*;

      public class URLTest {

          public static void main(String args[]) {
              try {
                  URL url1 = new URL("http://1234567@somehost");
                  System.out.println("url1: " + url1);
                  System.out.println("userInfo: " + url1.getUserInfo());
                  System.out.println("--------------------------------");
                  URL url2 = new URL("http://123456@somehost");
                  System.out.println("url2: " + url2);
                  System.out.println("userInfo: " + url2.getUserInfo());
                  System.out.println("--------------------------------");
                  if (url2.getUserInfo() == null) System.out.println("Test failed");
                  else System.out.println("Test passed");
              } catch (IOException e) {
                  System.out.println("error occured :" + e);
              }
          }
      }
      -------------------------------Output from the test---------------------
      url1: http://1234567@somehost
      userInfo: 1234567
      --------------------------------
      url2: http://123456@somehost
      userInfo: null
      --------------------------------
      Test failed
      ------------------------------------------------------------------------

      ======================================================================

            ywangsunw Yingxian Wang (Inactive)
            fdasunw Fda Fda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: