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

File constructors handle trailing "/" inconsistently

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0, 1.4.1
    • core-libs
    • generic, x86
    • generic, linux

      Name: rmT116609 Date: 08/13/2002


       FULL PRODUCT VERSION :
       java version "1.4.0_01"
       Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
       Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

       and:

       java version "1.4.1-beta"
       Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b14)
       Java HotSpot(TM) Client VM (build 1.4.1-beta-b14, mixed mode)



       FULL OPERATING SYSTEM VERSION :
       Linux 2.4.x

       ADDITIONAL OPERATING SYSTEMS :
       Windows 2000

      A DESCRIPTION OF THE PROBLEM :
      Case 1:

      File f1 = new File("/tmp");
      File f2 = new File "/tmp/"); //note trailing slash

      f1.equals(f2) is TRUE

      Now consider Case 2:

      f1 = new File("/tmp", "");
      f2 = new File("/tmp", "/"); //note trailing slash

      f1.equals(f2) is now FALSE !

      Note, in both cases, the files represented are exactly
      the same and in both cases one file ends with "/" while
      the other does not. Regardless, equals() is true in the
      former and false in the latter case.

      Note, this problem happens BOTH in Win2K and linux.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample program


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected: case1 and case 2 would both be true.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      public class FileTest
      {
      public static void main (String args[])
          {
          // CASE 1
          File f1 = new File("/tmp");
          File f2 = new File("/tmp/"); //note trailing slash
          System.out.println("case 1:" + f1.equals(f2));

          // CASE 2
          f1 = new File("/tmp", "");
          f2 = new File("/tmp", "/"); //note trailing slash
          System.out.println("case 2:" + f1.equals(f2));
          }
      }

      ---------- END SOURCE ----------
      (Review ID: 160702)
      ======================================================================

            bpb Brian Burkhalter
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: