question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Symbolic link without actual file link caused FileNotFoundException

See original GitHub issue

At 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)

  1. touch file
  2. ln -s file link
  3. run ZipUtil::pack to pack the directory contains file create above
  4. rm file
  5. 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
toomasrcommented, May 15, 2019

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.

0reactions
goxr3pluscommented, Jul 9, 2019

Yes let’s throw Java 6 and move on Java 7 . Very few companies are still using Java 6 . @toomasr

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found