From d9ecc5b3e66c6dc5e003b4af7a21209497849104 Mon Sep 17 00:00:00 2001 From: Kaiyuan Wang Date: Tue, 12 Feb 2019 20:51:05 -0800 Subject: [PATCH] Update the code to handle the following case: Imagine a test class import a src class but does not cover any lines in the src class. Assume that the test class only has a test method testExecNothing() and this method is executed before another test method testExecSomething() in another test class. Assume the test method testExecSomething() covers some lines in the src class. In the original implementation, testExecNothing() shares the same hitArray as testExecSomething() and this may lead to incorrect computation of the suspiciousness scores. For example, if testExecSomething() fails, then all lines covered by testExecSomething() will be treated as they are executed twice as many times as they actually are because testExecNothing()'s hitArray is updated by testExecSomething(). --- .../java/com/gzoltar/core/runtime/Collector.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/com.gzoltar.core/src/main/java/com/gzoltar/core/runtime/Collector.java b/com.gzoltar.core/src/main/java/com/gzoltar/core/runtime/Collector.java index 1b22c7b5..edbfd1ad 100644 --- a/com.gzoltar.core/src/main/java/com/gzoltar/core/runtime/Collector.java +++ b/com.gzoltar.core/src/main/java/com/gzoltar/core/runtime/Collector.java @@ -138,18 +138,16 @@ public synchronized void endTransaction(final String transactionName, String hash = entry.getKey(); boolean[] hitArray = entry.getValue().getRight(); - if (!ArrayUtils.containsValue(hitArray, true)) { - // although the class has been loaded and instrumented, no line has been covered - activity.put(hash, - new ImmutablePair(entry.getValue().getLeft(), hitArray)); - continue; - } - boolean[] cloneHitArray = new boolean[hitArray.length]; System.arraycopy(hitArray, 0, cloneHitArray, 0, hitArray.length); activity.put(hash, new ImmutablePair(entry.getValue().getLeft(), cloneHitArray)); + if (!ArrayUtils.containsValue(hitArray, true)) { + // although the class has been loaded and instrumented, no line has been covered + continue; + } + // reset probes for (int i = 0; i < hitArray.length; i++) { hitArray[i] = false;