misc cleanup

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@7346 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Brian Remedios
2011-09-25 04:00:29 +00:00
parent 5fe7f691e9
commit 27e8668ba0
2 changed files with 12 additions and 19 deletions

View File

@ -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.

View File

@ -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;
/**
* <p>A console renderer with optional color support under *nix systems.</p>
@ -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 {