Skip to content
Snippets Groups Projects
Commit 053987c7 authored by brinn's avatar brinn
Browse files

fix: race condition in StreamReaderGobbler

SVN: 647
parent 55a78861
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.Semaphore;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
......@@ -105,10 +106,12 @@ class SVNUtilities
private static final class StreamReaderGobbler
{
private final Semaphore waitForReadingFinishedSemaphore = new Semaphore(1);
private final List<String> lines = new ArrayList<String>();
StreamReaderGobbler(final InputStream stream)
StreamReaderGobbler(final InputStream stream) throws InterruptedException
{
waitForReadingFinishedSemaphore.acquire();
new Thread()
{
@Override
......@@ -116,26 +119,33 @@ class SVNUtilities
{
try
{
synchronized (this)
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null)
{
final BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
while ((line = reader.readLine()) != null)
{
lines.add(line);
}
lines.add(line);
}
} catch (IOException ex)
{
throw new EnvironmentFailureException("Couldn't gobble stream content", ex);
} finally
{
waitForReadingFinishedSemaphore.release();
}
}
}.start();
}
synchronized List<String> getLines()
List<String> getLines() throws InterruptedException
{
return lines;
waitForReadingFinishedSemaphore.acquire();
try
{
return lines;
} finally
{
waitForReadingFinishedSemaphore.release();
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment