ADDITIONAL SYSTEM INFORMATION :
Ubuntu 16.04 x64
java version "1.8.0_172"
A DESCRIPTION OF THE PROBLEM :
reproduce steps:
1. cd /tmp; touch a1.txt
2. in /tmp, create FileGetParentFileNull.java
//-------------------------------
import java.io.File;
import java.io.IOException;
public class FileGetParentFileNull {
public static void workaround() throws IOException {
File f = new File("a1.txt");
File f2 = new File(f.getCanonicalPath());
System.out.println("file exist: " + f2.exists());
File dir = f2.getParentFile();
System.out.println("dir: " + dir);
}
public static void main(String[] args) throws Exception {
File f = new File("a1.txt");
System.out.println("file exist: " + f.exists());
File dir = f.getParentFile(); // dir return null , but why ?
System.out.println("dir: " + dir);
System.out.println("----------------------------");
workaround();
}
}
//-------------------------------
3. javac FileGetParentFileNull.java
4. java FileGetParentFileNull
5. then in the first time, getParentFile() return null. seems bug.
Thanks!
Ubuntu 16.04 x64
java version "1.8.0_172"
A DESCRIPTION OF THE PROBLEM :
reproduce steps:
1. cd /tmp; touch a1.txt
2. in /tmp, create FileGetParentFileNull.java
//-------------------------------
import java.io.File;
import java.io.IOException;
public class FileGetParentFileNull {
public static void workaround() throws IOException {
File f = new File("a1.txt");
File f2 = new File(f.getCanonicalPath());
System.out.println("file exist: " + f2.exists());
File dir = f2.getParentFile();
System.out.println("dir: " + dir);
}
public static void main(String[] args) throws Exception {
File f = new File("a1.txt");
System.out.println("file exist: " + f.exists());
File dir = f.getParentFile(); // dir return null , but why ?
System.out.println("dir: " + dir);
System.out.println("----------------------------");
workaround();
}
}
//-------------------------------
3. javac FileGetParentFileNull.java
4. java FileGetParentFileNull
5. then in the first time, getParentFile() return null. seems bug.
Thanks!