Symbolic link without actual file link caused FileNotFoundException
See original GitHub issueAt https://github.com/zeroturnaround/zt-zip/blob/master/src/main/java/org/zeroturnaround/zip/ZipUtil.java#L1736 - String[] filenames = dir.list(); doesn’t guarantee return the list of files which are exists in the directory. If there is a symbolic link which link to not exists file, dir.list will return the file name but access the file will throw FileNotFoundException.
Steps to reproduce (must at Linux environment)
- touch file
- ln -s file link
- run ZipUtil::pack to pack the directory contains file create above
- rm file
- observe the exception. FileNotFoundException
The solution should always ensure the file is exists.
for (int i = 0; i < filenames.length; i++) { String filename = filenames[i]; File file = new File(dir, filename) if(!file.exists()) { continue; }
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Broken symlink file throws FileNotFoundException but passes ...
1 Answer 1 ... This behavior kind of makes sense - the file (symbolic link) exists, but you can't read it because it...
Read more >Links, Symbolic or Otherwise (The Java™ Tutorials ...
This Java tutorial describes exceptions, basic input/output, concurrency, regular expressions, and the platform environment.
Read more >FileContext (Apache Hadoop Main 3.3.4 API)
The FileContext class provides an interface for users of the Hadoop file system. It exposes a number of file system operations, e.g. create,...
Read more >Invalid symbolic links get archived but cannot be copied using ...
The copyartifact plugin fails to properly handle symlinks from a slave machine. When you create the symlink and archive it, the symlink returns...
Read more >Create a Symbolic Link with Java - Baeldung
Soft/Symbolic link is a file pointer that behaves as the file that is linking to – if the target file gets deleted then...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think I’ll throw away the current copying, start relying on Java 7 and bump the requirements. Anybody still on Java 6 will have to do with the current functionality.
Yes let’s throw Java 6 and move on Java 7 . Very few companies are still using Java 6 . @toomasr