Skip to content

Commit f6c8dcc

Browse files
author
Niall Pemberton
committed
IO-177 Should be handling InterruptedException when sleeping - not calling the exception handler
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1005921 13f79535-47bb-0310-9956-ffa450edef68
1 parent ec8a341 commit f6c8dcc

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/main/java/org/apache/commons/io/input/Tailer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,10 @@ public void run() {
192192
}
193193

194194
if (reader == null) {
195-
Thread.sleep(delay);
195+
try {
196+
Thread.sleep(delay);
197+
} catch (InterruptedException e) {
198+
}
196199
} else {
197200
// The current position in the file
198201
position = end ? file.length() : 0;
@@ -250,8 +253,10 @@ public void run() {
250253
position = readLines(reader);
251254
}
252255
}
253-
254-
Thread.sleep(delay);
256+
try {
257+
Thread.sleep(delay);
258+
} catch (InterruptedException e) {
259+
}
255260
}
256261

257262
} catch (Exception e) {

src/test/java/org/apache/commons/io/input/TailerTest.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ public void testTailer() throws Exception {
4545
File file = new File(getTestDirectory(), "tailer1-test.txt");
4646
createFile(file, 0);
4747
TestTailerListener listener = new TestTailerListener();
48-
Tailer tailer = start(file, listener, delay, false);
48+
final Tailer tailer = new Tailer(file, listener, delay, false);
49+
final Thread thread = new Thread(tailer);
50+
thread.start();
4951

5052
// Write some lines to the file
5153
write(file, "Line one", "Line two");
@@ -86,6 +88,7 @@ public void testTailer() throws Exception {
8688

8789
// Stop
8890
tailer.stop();
91+
thread.interrupt();
8992
Thread.sleep(delay * 2);
9093
write(file, "Line five");
9194
assertEquals("4 line count", 0, listener.getLines().size());
@@ -95,14 +98,6 @@ public void testTailer() throws Exception {
9598
assertEquals("fileRotated should be be called", 1 , listener.rotated);
9699
}
97100

98-
/** Start a tailer */
99-
private Tailer start(File file, TailerListener listener, long delay, boolean end) {
100-
Tailer tailer = new Tailer(file, listener, delay, end);
101-
Thread thread = new Thread(tailer);
102-
thread.start();
103-
return tailer;
104-
}
105-
106101
/** Append some lines to a file */
107102
private void write(File file, String... lines) throws Exception {
108103
FileWriter writer = null;

0 commit comments

Comments
 (0)