diff --git a/pmd/src/net/sourceforge/pmd/PMD.java b/pmd/src/net/sourceforge/pmd/PMD.java index 8faba57301..68d6a92641 100644 --- a/pmd/src/net/sourceforge/pmd/PMD.java +++ b/pmd/src/net/sourceforge/pmd/PMD.java @@ -42,6 +42,7 @@ import net.sourceforge.pmd.lang.xpath.Initializer; import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.util.Benchmark; import net.sourceforge.pmd.util.FileUtil; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.datasource.DataSource; import net.sourceforge.pmd.util.log.ConsoleLogHandler; import net.sourceforge.pmd.util.log.ScopedLogHandlersManager; @@ -200,11 +201,8 @@ public class PMD { } catch (Exception e) { throw new PMDException("Error while processing " + ctx.getSourceCodeFilename(), e); } finally { - try { - reader.close(); - } catch (IOException e) { + IOUtil.closeQuietly(reader); } - } } // This method is the main entry point for command line usage. diff --git a/pmd/src/net/sourceforge/pmd/renderers/TextColorRenderer.java b/pmd/src/net/sourceforge/pmd/renderers/TextColorRenderer.java index f2b7a0d467..86f3ec3632 100644 --- a/pmd/src/net/sourceforge/pmd/renderers/TextColorRenderer.java +++ b/pmd/src/net/sourceforge/pmd/renderers/TextColorRenderer.java @@ -16,6 +16,7 @@ import java.util.Properties; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.util.IOUtil; /** *
A console renderer with optional color support under *nix systems.
@@ -166,25 +167,19 @@ public class TextColorRenderer extends AbstractAccumulatingRenderer { * @return a trimmed line of source code */ private String getLine(String sourceFile, int line) { - String code = null; - BufferedReader br = null; - try { - br = new BufferedReader(getReader(sourceFile)); - for (int i = 0; line > i; i++) { - code = br.readLine().trim(); - } - } catch (IOException ioErr) { - ioErr.printStackTrace(); - } finally { - if (br != null) { + String code = null; + BufferedReader br = null; try { - br.close(); + br = new BufferedReader(getReader(sourceFile)); + for (int i = 0; line > i; i++) { + code = br.readLine().trim(); + } } catch (IOException ioErr) { ioErr.printStackTrace(); + } finally { + IOUtil.closeQuietly(br); } - } - } - return code; + return code; } protected Reader getReader(String sourceFile) throws FileNotFoundException {