]> source.dussan.org Git - sonarqube.git/commitdiff
fix quality flaws on BatchReportReaderImpl
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 2 Jun 2015 15:03:24 +0000 (17:03 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 2 Jun 2015 16:01:17 +0000 (18:01 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/batch/BatchReportReaderImpl.java

index 13cb2d6f960450fe597fa487c2595f2e434fcc0c..c48e0289b1ab81b09d129399fbd36d78d05dd32f 100644 (file)
@@ -125,38 +125,45 @@ public class BatchReportReaderImpl implements BatchReportReader {
   public CloseableIterator<String> 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<String>() {
-        @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<String> {
+    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<BatchReport.Test> readTests(int testFileRef) {
     File file = delegate.readTests(testFileRef);