commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kristian Rosenvold (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (IO-448) FileUtils.waitFor(...) swallows thread interrupted status
Date Fri, 19 Jun 2015 18:25:01 GMT

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

Kristian Rosenvold commented on IO-448:
---------------------------------------

Fixed in r1686477, thanks for the patch !

> FileUtils.waitFor(...) swallows thread interrupted status
> ---------------------------------------------------------
>
>                 Key: IO-448
>                 URL: https://issues.apache.org/jira/browse/IO-448
>             Project: Commons IO
>          Issue Type: Bug
>          Components: Utilities
>    Affects Versions: 2.4
>            Reporter: Björn Buchner
>            Priority: Minor
>
> The method waits for a file to appear for a given amount of time. To do so it calls Thread.sleep
several times. If the thread is interrupted, the interrupt will be ignored by catching the
ThreadInterrupted exception and waiting further.
> Catching the ThreadInterrupted exception automatically clears the thread's interrupted
flag. Consequently the calling method has no chance to detect whether the thread was interrupted.
A possible solution is to restore the interrupted status before returning - something like
this:
> {code}
>     public static boolean waitFor(File file, int seconds) {
>         int timeout = 0;
>         int tick = 0;
>         boolean wasInterrupted = false;
>         try {
>             while (!file.exists()) {
>                 // ...
>                 try {
>                     Thread.sleep(100);
>                 } catch (InterruptedException ignore) {
>                     wasInterrupted = true;
>                 } catch (Exception ex) {
>                     break;
>                 }
>             }
>             return true;
>         } finally {
>             if (wasInterrupted) {
>                    Thread.currentThread.interrupt();
>             }
>         }
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message