[ 
https://issues.apache.org/jira/browse/IO-856?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17852938#comment-17852938
 ] 

Thomas Hartwig commented on IO-856:
-----------------------------------

Distributor ID: Ubuntu 
Description:    Ubuntu 22.04.4 LTS 
Release:        22.04 
Codename:       jammy


java.vm.vendor: Oracle Corporation
sun.arch.data.model: 64
java.vendor.url: https://java.oracle.com/
user.timezone: Europe/Berlin
java.vm.specification.version: 17
os.name: Linux
sun.java.launcher: SUN_STANDARD
user.country: US
sun.boot.library.path: /opt/graalvm-jdk-17.0.10+11.1/lib
jdk.debug: release
sun.cpu.endian: little
user.home: /home/th
user.language: en
java.specification.vendor: Oracle Corporation
java.vm.specification.vendor: Oracle Corporation
java.specification.name: Java Platform API Specification
jdk.module.main.class: test.ApacheBug
jdk.module.main: com.itth.test
sun.management.compiler: HotSpot 64-Bit Tiered Compilers
java.runtime.version: 17.0.10+11-LTS-jvmci-23.0-b27
user.name: th
path.separator: :
os.version: 5.15.0-107-lowlatency
java.runtime.name: Java(TM) SE Runtime Environment
file.encoding: UTF-8
java.vm.name: Java HotSpot(TM) 64-Bit Server VM
java.vendor.version: Oracle GraalVM 17.0.10+11.1
java.vendor.url.bug: https://bugreport.java.com/bugreport/
java.io.tmpdir: /tmp
java.version: 17.0.10
user.dir: /home/th/dev/ai/idea-projects/uvis
os.arch: amd64
java.vm.specification.name: Java Virtual Machine Specification
native.encoding: UTF-8
java.library.path: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib
java.vm.info: mixed mode, sharing
java.vendor: Oracle Corporation
java.vm.version: 17.0.10+11-LTS-jvmci-23.0-b27
sun.io.unicode.encoding: UnicodeLittle
java.class.version: 61.0

> ListFiles should not fail on vanishing files
> --------------------------------------------
>
>                 Key: IO-856
>                 URL: https://issues.apache.org/jira/browse/IO-856
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.16.1
>            Reporter: Thomas Hartwig
>            Assignee: Gary D. Gregory
>            Priority: Major
>
> ListFiles crashes when vanishing files are involved while listing, ListFiles 
> should simply list, the application should care of if files are not existent 
> any more:
> <pre>
> java.io.UncheckedIOException: java.nio.file.NoSuchFileException: 
> /tmp/20b50a15-b84e-4a9a-953e-223452dac994/a914fa55-50f7-4de0-8ca6-1fd84f10b29a.png
>     at 
> java.base/java.nio.file.FileTreeIterator.fetchNextIfNeeded(FileTreeIterator.java:87)
>     at 
> java.base/java.nio.file.FileTreeIterator.hasNext(FileTreeIterator.java:103)
>     at java.base/java.util.Iterator.forEachRemaining(Iterator.java:132)
>     at 
> java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
>     at 
> java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
>     at 
> java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
>     at 
> java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
>     at 
> java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
>     at 
> java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
>     at 
> org.apache.commons.io@2.16.1/org.apache.commons.io.FileUtils.toList(FileUtils.java:3025)
>     at 
> org.apache.commons.io@2.16.1/org.apache.commons.io.FileUtils.listFiles(FileUtils.java:2314)
>     at com.itth.test/test.ApacheBug.lambda$main$1(ApacheBug.java:39)
>     at java.base/java.lang.Thread.run(Thread.java:842)
> Caused by: java.nio.file.NoSuchFileException: 
> /tmp/20b50a15-b84e-4a9a-953e-223452dac994/a914fa55-50f7-4de0-8ca6-1fd84f10b29a.png
>     at 
> java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:92)
>     at 
> java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:106)
>     at 
> java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
>     at 
> java.base/sun.nio.fs.UnixFileAttributeViews$Basic.readAttributes(UnixFileAttributeViews.java:55)
>     at 
> java.base/sun.nio.fs.UnixFileSystemProvider.readAttributes(UnixFileSystemProvider.java:148)
>     at 
> java.base/sun.nio.fs.LinuxFileSystemProvider.readAttributes(LinuxFileSystemProvider.java:99)
>     at java.base/java.nio.file.Files.readAttributes(Files.java:1851)
>     at 
> java.base/java.nio.file.FileTreeWalker.getAttributes(FileTreeWalker.java:226)
>     at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:277)
>     at java.base/java.nio.file.FileTreeWalker.next(FileTreeWalker.java:374)
>     at 
> java.base/java.nio.file.FileTreeIterator.fetchNextIfNeeded(FileTreeIterator.java:83)
>     ... 12 more
> </pre>
> Use this to reproduce:
> <pre>
> package test;
> import org.apache.commons.io.FileUtils;
> import java.io.BufferedOutputStream;
> import java.io.File;
> import java.io.FileOutputStream;
> import java.io.IOException;
> import java.nio.charset.StandardCharsets;
> import java.nio.file.Path;
> import java.util.Collection;
> import java.util.UUID;
> public class ApacheBug {
> public static void main(String[] args) {
> // create random directory in tmp, create the directory if it does not exist
> final File dir = FileUtils.getTempDirectory();
> if (!dir.exists()) {
> if (!dir.mkdirs()) {
> throw new RuntimeException("could not create image file path: " + 
> dir.getAbsolutePath());
> }
> }
> // create random file in the directory
> new Thread(() -> {
> try {
> while (true) {
> final File file = Path.of(dir.getAbsolutePath(), UUID.randomUUID().toString() 
> + ".png").toFile();
> new BufferedOutputStream(new 
> FileOutputStream(file)).write("TEST".getBytes(StandardCharsets.UTF_8));
> file.delete();
> }
> } catch (IOException e) {
> e.printStackTrace();
> }
> }).start();
> new Thread(() -> {
> try {
> while (true) {
> final Collection<File> files = FileUtils.listFiles(dir, new String[]\{"png"}, 
> true);
> System.out.println(files.size());
> }
> } catch (Exception e) {
> e.printStackTrace();
> }
> }).start();
> try {
> Thread.sleep(10000);
> } catch (InterruptedException e) {
> Thread.currentThread().interrupt();
> }
> }
> }
> </pe>
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to