From 27e8668ba0d9ddf8fd0f6d5822f35563b6ce1db8 Mon Sep 17 00:00:00 2001 From: Brian Remedios Date: Sun, 25 Sep 2011 04:00:29 +0000 Subject: [PATCH] misc cleanup git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7346 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/src/net/sourceforge/pmd/PMD.java | 6 ++--- .../pmd/renderers/TextColorRenderer.java | 25 ++++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) 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 {