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

getRef() in URL works differently depending on how the object is constructed

XMLWordPrintable

    • 1.1
    • sparc
    • solaris_2.5
    • Not verified


      URL's getRef() method is supposed to get the
      part of the URL that follows the # sign. For example, in
      the following URL

      http://java.sun.com/tutoria/index.html#DOWNLOADING

      getRef() should return the string

      DOWNLOADING

      getRef() returns different values depending on the constructor
      that you use to create the URL. Here's small test program
      that illustrates the problem:

      import java.net.*;

      class ParseBug {
          public static void main(String args[]) {
              URL aURL = null;
              URL bURL = null;
              URL cURL = null;
              URL dURL = null;
              URL tempURL = null;
              try {
                  aURL = new URL("http://java.sun.com/tutorial/intro.html#DOWNLOADING");
                  bURL = new URL("http", "java.sun.com", "/tutorial/intro.html#DOWNLOADING");
                  cURL = new URL("http", "java.sun.com", 80, "/tutorial/intro.html#DOWNLOADING");
                  tempURL = new URL("http://java.sun.com/");
                  dURL = new URL(tempURL, "tutorial/intro.html#DOWNLOADING");
              } catch (MalformedURLException e) {
                  ;
              }
              System.out.println("ref = " + aURL.getRef()); // prints DOWNLOADING
              System.out.println("ref = " + bURL.getRef()); // prints null
              System.out.println("ref = " + cURL.getRef()); // prints null
              System.out.println("ref = " + dURL.getRef()); // prints DOWNLOADING
          }
      }


      The output from the program is:

      ref = DOWNLOADING
      ref = null
      ref = null
      ref = DOWNLOADING


            djbrown David Brown (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: