diff --git a/pmd/src/net/sourceforge/pmd/renderers/SummaryHTMLRenderer.java b/pmd/src/net/sourceforge/pmd/renderers/SummaryHTMLRenderer.java
index 39574dab58..a2a8fbaa8a 100644
--- a/pmd/src/net/sourceforge/pmd/renderers/SummaryHTMLRenderer.java
+++ b/pmd/src/net/sourceforge/pmd/renderers/SummaryHTMLRenderer.java
@@ -48,22 +48,22 @@ public class SummaryHTMLRenderer extends AbstractAccumulatingRenderer {
* @throws IOException
*/
public void renderSummary() throws IOException {
- StringBuffer buf = new StringBuffer(500);
- buf.append("
Summary
");
- buf.append("");
- buf.append("Rule name | ");
- buf.append("Number of violations | ");
- writer.write(buf.toString());
- Map summary = report.getSummary();
- for (Map.Entry entry : summary.entrySet()) {
- String ruleName = entry.getKey();
- buf.setLength(0);
- buf.append("");
- buf.append("" + ruleName + " | ");
- buf.append("" + entry.getValue().intValue() + " | ");
- buf.append("
");
- writer.write(buf.toString());
- }
- writer.write("
");
+ StringBuilder buf = new StringBuilder(500);
+ buf.append("Summary
");
+ buf.append("");
+ buf.append("Rule name | ");
+ buf.append("Number of violations | ");
+ writer.write(buf.toString());
+ Map summary = report.getSummary();
+ for (Map.Entry entry : summary.entrySet()) {
+ String ruleName = entry.getKey();
+ buf.setLength(0);
+ buf.append("");
+ buf.append("" + ruleName + " | ");
+ buf.append("" + entry.getValue().intValue() + " | ");
+ buf.append("
");
+ writer.write(buf.toString());
+ }
+ writer.write("
");
}
}
diff --git a/pmd/src/net/sourceforge/pmd/util/Benchmark.java b/pmd/src/net/sourceforge/pmd/util/Benchmark.java
index 252475a786..8f9a38734c 100644
--- a/pmd/src/net/sourceforge/pmd/util/Benchmark.java
+++ b/pmd/src/net/sourceforge/pmd/util/Benchmark.java
@@ -147,12 +147,13 @@ public class Benchmark {
p.getConfiguration().setDefaultLanguageVersion(languageVersion);
RuleContext ctx = new RuleContext();
long start = System.currentTimeMillis();
+ Reader reader = null;
for (DataSource dataSource: dataSources) {
- Reader reader = new InputStreamReader(dataSource.getInputStream());
- ctx.setSourceCodeFilename(dataSource.getNiceFileName(false, null));
- p.processFile(reader, ruleSets, ctx);
- reader.close();
- }
+ reader = new InputStreamReader(dataSource.getInputStream());
+ ctx.setSourceCodeFilename(dataSource.getNiceFileName(false, null));
+ p.processFile(reader, ruleSets, ctx);
+ IOUtil.closeQuietly(reader);
+ }
long end = System.currentTimeMillis();
long elapsed = end - start;
results.add(new Result(elapsed, rule));
diff --git a/pmd/src/net/sourceforge/pmd/util/ClasspathClassLoader.java b/pmd/src/net/sourceforge/pmd/util/ClasspathClassLoader.java
index 6b5f8d9a79..fe48c5bb5d 100644
--- a/pmd/src/net/sourceforge/pmd/util/ClasspathClassLoader.java
+++ b/pmd/src/net/sourceforge/pmd/util/ClasspathClassLoader.java
@@ -65,15 +65,8 @@ public class ClasspathClassLoader extends URLClassLoader {
urls.add(createURLFromPath(line));
}
}
- in.close();
} finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- LOG.log(Level.SEVERE, "IOException while closing InputStream", e);
- }
- }
+ IOUtil.closeQuietly(in);
}
}
@@ -87,17 +80,9 @@ public class ClasspathClassLoader extends URLClassLoader {
*/
@Override
public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(getClass().getSimpleName());
+ StringBuilder sb = new StringBuilder(getClass().getSimpleName());
sb.append("[[");
- boolean first = true;
- for (URL url : getURLs()) {
- if (!first) {
- sb.append(':');
- }
- first = false;
- sb.append(url);
- }
+ StringUtil.asStringOn(sb, getURLs(), ":");
sb.append("] parent: ");
sb.append(getParent());
sb.append(']');
diff --git a/pmd/src/net/sourceforge/pmd/util/StringUtil.java b/pmd/src/net/sourceforge/pmd/util/StringUtil.java
index 9fbae1760a..9dc98ad1c5 100644
--- a/pmd/src/net/sourceforge/pmd/util/StringUtil.java
+++ b/pmd/src/net/sourceforge/pmd/util/StringUtil.java
@@ -304,6 +304,27 @@ public final class StringUtil {
sb.append(iter.next());
}
}
+
+ /**
+ * Copies the array items onto the string builder each delimited by the separator.
+ * Does nothing if the array is null or empty.
+ *
+ * @param sb StringBuilder
+ * @param items Object[]
+ * @param separator String
+ */
+ public static void asStringOn(StringBuilder sb, Object[] items, String separator) {
+
+ if (items == null | items.length == 0) { return; }
+
+ sb.append(items[0]);
+
+ for (int i=1; i