Name: dkR10031 Date: 05/30/2003
When the static instrumenter saves collected coverage data to an
existing coverage file it simply appends the data to the end of the file.
In particular, this can happen when a combination of '-save...' options is
specified. Such behaviour leads to duplicated classes in the resulting
coverage
file.
Even though JCov documentation does not specify static instrumenter
behaviour in such cases, it seems to be a bug. Data files with duplicated
classes are inappropriate for further processing and analysis.
To reproduce the bug run the script below. This script compiles
Hello.java, instruments all classes in '.' directory by the
Static Instrumenter using '-saveafter', '-saveatend', '-savebefore',
and '-savebegin' options, and after that prints out all duplicates of the
'CLASS: Hello' entry in the result java.jcov file.
------------ Hello.java Source Begin ---------
class A {
public static void a() {
System.out.println("AAA!");
}
}
class B {
public static void b() {
System.out.println("BBB!");
}
}
class C {
public static void c() {
System.out.println("CCC!");
}
}
class D {
public static void d() {
System.out.println("DDD!");
}
}
public class Hello {
public static void main(String[] args) {
A.a();
B.b();
C.c();
D.d();
System.out.println("Hello world!");
}
}
------------ Source End ----------------------
------------ Script Begin --------------------
#!/usr/bin/ksh
uname -a
export
JCOV_JAR=/net/linux-11/export/home/gary/QA.JCOV/ws/image/lib/jcov.jar
export CLASSPATH=${JCOV_JAR}:.
export JDK=/net/linux-15/export/home/java/jdk1.4.0/sparc
$JDK/bin/javac -Xjcov Hello.java
$JDK/bin/java -showversion com.sun.tdk.jcov.InstrMain -commonTimeStamp -savebefore=A.a -saveafter=B.b -savebegin=C.c -saveatend=D.d -overwrite .
$JDK/bin/java Hello
grep 'CLASS: Hello' java.jcov
------------ Script End ----------------------
------------ Output Begin --------------------
bash-2.03$ ksh runtest.ksh
SunOS novo148 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-80
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build
1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
AAA!
BBB!
CCC!
DDD!
Hello world!
CLASS: Hello [public]
CLASS: Hello [public]
CLASS: Hello [public]
CLASS: Hello [public]
------------ Output End ----------------------
======================================================================