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

File.list() needs to improve handling of symbolic links

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.3.1
    • core-libs
    • x86
    • linux



      Name: nt126004 Date: 10/16/2001


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

      Suppose Test is a directory created under /home/sanjoy. Under Test there is only
      one directory called t1 i.e. hiearchy is /home/sanjoy/Test/t1. Under t1 there
      are two files x.java and y.java. Now we have created a symbolic link of y.java named y
      also in the Test/t1 directory.


      The source code of T.java located at /home/sanjoy/ is given below.

      Now we run the program under two conditions:

      Cond-1: directory t1 has x.java , y.java and hard-link y as stated above.
      Cond-2: delete the y.java and run the program.

      Cond-1 Output:
      ==============
      File name : x.java
      File name : y.java
      File name : y

      Cond-2 Output:
      ==============
      File name : x.java
      Not a directory or file : y

      Now my question is:
      Why should we consider hard-link y , when source of the link ( here y.java ) is
      deleted , in listing ? Because it is neither a file nor a directory.

      One implementation of File.list() shoud not return symbolic links.
      Another implementation of File.list() should return symbolic links
      provided their sources do exist.

      Present implementation of File.list() returns symbolic links although their
      sources do not exist.
      In this situation I somehow filter the hard-link y.That means , for Cond-2 my
      desired output should be:

      Cond-2 Output:
      ==============
      File name : x.java


      Source code:

      import java.io.*;
      import java.lang.*;
       
      public class T{
          public static void main(String[] args){
              try{
                  File f = new File("Test/t1");
                  String[] list = f.list();
       
                  for ( int i = 0; i < list.length; i++ ){
                      File f1 = new File(f,list[i]);
       
                      if ( f1.isFile() || f1.isDirectory() ){
                          System.out.println("File name : " + f1.getName());
                      }else{
                          System.out.println("Not a directory or file : " +
      f1.getName());
                      }
                  }
              }catch(Exception e){}
          }
      }
      (Review ID: 133681)
      ======================================================================

            Unassigned Unassigned
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: