From 699fab7d1d406e9f29b47f6662cc9472f2e59e2e Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 2 Jun 2015 17:03:24 +0200 Subject: [PATCH] fix quality flaws on BatchReportReaderImpl --- .../batch/BatchReportReaderImpl.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) 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); -- 2.39.5