Fix code quality problems reported by Sonar.
diff --git a/org.jacoco.core/src/org/jacoco/core/JaCoCo.java b/org.jacoco.core/src/org/jacoco/core/JaCoCo.java
index 0cfca92..a60fc14 100644
--- a/org.jacoco.core/src/org/jacoco/core/JaCoCo.java
+++ b/org.jacoco.core/src/org/jacoco/core/JaCoCo.java
@@ -31,8 +31,11 @@
try {
final InputStream in = JaCoCo.class
.getResourceAsStream("jacoco.properties");
- properties.load(in);
- in.close();
+ try {
+ properties.load(in);
+ } finally {
+ in.close();
+ }
} catch (final IOException e) {
throw new AssertionError(e);
}
diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
index 0028f59..54f3795 100644
--- a/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
+++ b/org.jacoco.core/src/org/jacoco/core/analysis/Analyzer.java
@@ -177,8 +177,11 @@
}
} else {
final InputStream in = new FileInputStream(file);
- count += analyzeAll(in);
- in.close();
+ try {
+ count += analyzeAll(in);
+ } finally {
+ in.close();
+ }
}
return count;
}
diff --git a/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java b/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java
index 750b8e6..a5ef4f4 100644
--- a/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java
+++ b/org.jacoco.core/src/org/jacoco/core/analysis/NodeComparator.java
@@ -51,6 +51,9 @@
public NodeComparator second(final Comparator<ICoverageNode> second) {
final Comparator<ICoverageNode> first = this;
return new NodeComparator(null, null) {
+
+ private static final long serialVersionUID = -5515272752138802838L;
+
@Override
public int compare(final ICoverageNode o1, final ICoverageNode o2) {
final int result = first.compare(o1, o2);
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java b/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java
index 56d0380..359a5c1 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/analysis/MethodAnalyzer.java
@@ -252,11 +252,11 @@
for (final Instruction i : instructions) {
final int total = i.getBranches();
final int covered = i.getCoveredBranches();
- final ICounter instructions = covered == 0 ? CounterImpl.COUNTER_1_0
+ final ICounter instrCounter = covered == 0 ? CounterImpl.COUNTER_1_0
: CounterImpl.COUNTER_0_1;
- final ICounter branches = total > 1 ? CounterImpl.getInstance(total
- - covered, covered) : CounterImpl.COUNTER_0_0;
- coverage.increment(instructions, branches, i.getLine());
+ final ICounter branchCounter = total > 1 ? CounterImpl.getInstance(
+ total - covered, covered) : CounterImpl.COUNTER_0_0;
+ coverage.increment(instrCounter, branchCounter, i.getLine());
}
coverage.incrementMethodCounter();
}
diff --git a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java
index 1884500..b465901 100644
--- a/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java
+++ b/org.jacoco.core/src/org/jacoco/core/internal/flow/ClassProbesAdapter.java
@@ -104,10 +104,10 @@
super.visitEnd();
this.accept(new LabelFlowAnalyzer());
if (interfaceType) {
- final ProbeCounter counter = new ProbeCounter();
+ final ProbeCounter probeCounter = new ProbeCounter();
this.accept(new MethodProbesAdapter(
- EMPTY_METHOD_PROBES_VISITOR, counter));
- cv.visitTotalProbeCount(counter.count);
+ EMPTY_METHOD_PROBES_VISITOR, probeCounter));
+ cv.visitTotalProbeCount(probeCounter.count);
}
this.accept(new MethodProbesAdapter(methodProbes,
ClassProbesAdapter.this));
diff --git a/org.jacoco.core/src/org/jacoco/core/runtime/URLStreamHandlerRuntime.java b/org.jacoco.core/src/org/jacoco/core/runtime/URLStreamHandlerRuntime.java
index b57f13a..ccba86c 100644
--- a/org.jacoco.core/src/org/jacoco/core/runtime/URLStreamHandlerRuntime.java
+++ b/org.jacoco.core/src/org/jacoco/core/runtime/URLStreamHandlerRuntime.java
@@ -53,9 +53,9 @@
final Field field = URL.class.getDeclaredField("handlers");
field.setAccessible(true);
@SuppressWarnings("unchecked")
- final Map<String, URLStreamHandler> handlers = (Map<String, URLStreamHandler>) field
+ final Map<String, URLStreamHandler> map = (Map<String, URLStreamHandler>) field
.get(null);
- return handlers;
+ return map;
}
public void shutdown() {