From: Sébastien Lesaint Date: Tue, 2 Jun 2015 15:03:24 +0000 (+0200) Subject: fix quality flaws on BatchReportReaderImpl X-Git-Tag: 5.2-RC1~1685 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=699fab7d1d406e9f29b47f6662cc9472f2e59e2e;p=sonarqube.git fix quality flaws on BatchReportReaderImpl --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java b/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java index 13cb2d6f960..c48e0289b1a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java @@ -125,38 +125,45 @@ public class BatchReportReaderImpl implements BatchReportReader { public CloseableIterator readFileSource(int fileRef) { File file = delegate.readFileSource(fileRef); if (file == null) { - throw new IllegalStateException("Unable to find source for file #" + fileRef + ". File does not exist: " + file); + throw new IllegalStateException("Unable to find source for file #" + fileRef); } try { - final LineIterator lineIterator = IOUtils.lineIterator(FileUtils.openInputStream(file), StandardCharsets.UTF_8); - return new CloseableIterator() { - @Override - public boolean hasNext() { - return lineIterator.hasNext(); - } - - @Override - public String next() { - return lineIterator.next(); - } - - @Override - protected String doNext() { - // never called anyway - throw new NoSuchElementException("Empty closeable Iterator has no element"); - } - - @Override - protected void doClose() throws Exception { - lineIterator.close(); - } - }; + return new CloseableLineIterator(IOUtils.lineIterator(FileUtils.openInputStream(file), StandardCharsets.UTF_8)); } catch (IOException e) { throw new IllegalStateException("Fail to traverse file: " + file, e); } } + private static class CloseableLineIterator extends CloseableIterator { + private final LineIterator lineIterator; + + public CloseableLineIterator(LineIterator lineIterator) { + this.lineIterator = lineIterator; + } + + @Override + public boolean hasNext() { + return lineIterator.hasNext(); + } + + @Override + public String next() { + return lineIterator.next(); + } + + @Override + protected String doNext() { + // never called anyway + throw new NoSuchElementException("Empty closeable Iterator has no element"); + } + + @Override + protected void doClose() throws Exception { + lineIterator.close(); + } + } + @Override public CloseableIterator readTests(int testFileRef) { File file = delegate.readTests(testFileRef);