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

equal "file:" URLs aren't claiming that they're equal to each other

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • core-libs
    • None
    • beta3
    • sparc
    • solaris_8
    • Verified

      Starting with the 9/21 Merlin nightly build (i.e. due to a change integrated subsequent to promoted build 80), it appears that URL objects created from File.toURL are not correctly reported as equal to equivalent URL objects constructed from the URL(String) constructor. The following test case demonstrates the bug:

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

      public class URLEquals {
          public static void main(String[] args) throws Exception {
      File f0 = new File(args[0]);
      URL u0 = f0.toURL();
      System.err.println("\nu0: " + u0);

      File f1 = new File(args[0]);
      URL u1 = f1.toURL();
      System.err.println("\nu1: " + u1);
      showEquals("u0", u0, "u1", u1);

      String s1 = u1.toExternalForm();
      URL u2 = new URL(s1);
      System.err.println("\nu2: " + u2);
      showEquals("u1", u1, "u2", u2);

      String s2 = u2.toExternalForm();
      URL u3 = new URL(s2);
      System.err.println("\nu3: " + u3);
      showEquals("u2", u2, "u3", u3);
          }

          private static void showEquals(String n1, Object o1,
      String n2, Object o2)
          {
      System.err.println(n1 + ".equals(" + n2 + ") returns " +
      (o1.equals(o2) ? "TRUE" : "FALSE"));
      System.err.println(n2 + ".equals(" + n1 + ") returns " +
      (o2.equals(o1) ? "TRUE" : "FALSE"));
          }
      }

      It produces the following result when run against the 9/21 nightly Merlin build (and the 9/22 and 9/23 nightly builds as well):

      [terrier] 236 % which java
      /net/mizu.sfbay/usr/re/jdk/jdk1.4/binaries/solsparc/b81-2001-09-21/j2sdk1.4.0/bin/java
      [terrier] 237 % java -version
      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b81)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b81, mixed mode)
      [terrier] 238 % java URLEquals .

      u0: file:/tmp/./

      u1: file:/tmp/./
      u0.equals(u1) returns TRUE
      u1.equals(u0) returns TRUE

      u2: file:/tmp/./
      u1.equals(u2) returns FALSE
      u2.equals(u1) returns FALSE

      u3: file:/tmp/./
      u2.equals(u3) returns TRUE
      u3.equals(u2) returns TRUE

      [See Comments for further speculation.]

            ywangsunw Yingxian Wang (Inactive)
            peterjones Peter Jones (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: