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

URLStreamHandler.equals(URL,URL) ignores authority field

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.6



      Name: dfC67450 Date: 10/05/99



      equals, sameFile, hostsEqual of java.net.URLStreamHandler return true
      since JDK build 1.3.0-G despite that authority fields of URLs are different.
      In JDK build 1.3beta-O these methods return false. Javadoc does not
      clarify the behaviour.

      Maybe it is Javadoc bug.

      Here is the test demonstrating the bug:

      ---------------------------------------------
      import java.net.*;
      import java.io.*;

      public class Test {
          public static void main (String args[]){


              try {
                  URL url1 = new URL("http://he@host/file#ref");
                  URL url2 = new URL("http://she@host/file#ref");
                  USH ush = new USH();
                  System.out.println("url1: " + url1);
                  System.out.println("url2: " + url2);
                  System.out.println("equals: " + ush.equals(url1, url2));
                  System.out.println("hostsEqual: " + ush.hostsEqual(url1, url2));
                  System.out.println("sameFile: " + ush.sameFile(url1, url2));
              } catch (Exception e) {
                  System.out.println("Unexpected exception:" + e);
                  return;
              }
          }
      }

      class USH extends URLStreamHandler {
          public URLConnection openConnection(URL u) throws IOException {
              return (URLConnection)null;
          }

          public boolean equals(URL u1, URL u2) {
              return super.equals(u1, u2);
          }

          public boolean sameFile(URL u1, URL u2) {
              return super.sameFile(u1, u2);
          }

          public boolean hostsEqual(URL u1, URL u2) {
              return super.hostsEqual(u1, u2);
          }

      }
      ------------- output for build 1.3beta-O-release ---------
      url1: http://he@host/file#ref
      url2: http://she@host/file#ref
      equals: false
      hostsEqual: false
      sameFile: false
      ------------- output for build 1.3.0-G -------------------
      url1: http://he@host/file#ref
      url2: http://she@host/file#ref
      equals: true
      hostsEqual: true
      sameFile: true
      ----------------------------------------------------------

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

            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: