Hi Anton,
there are two reasons for this design:
JaCoCo should support multiple versions of classes in the same VM. This
is a typical scenario in application servers or OSGi container. I
understand that in some situations (like unit testing with mocking
framework) this feature is questionable.
The other reason is a limitation of the way hot JaCoCo implements code
coverage analysis: At runtime (instrumentation) as well as during
analysis every class file is analyzed for its internal control
structures. For the specific control structure a list of positions for
probes if calculated, every probe gets an index 0...n. For
instrumentation extra byte code is inserted at these positions which
toggles a flag with the respective index. The JaCoCo runtime collects
the flags for every class (represented as an boolean array) and e.g.
writes it to the exec file.
During analysis the same class is analyzed again for its internal
control structure to calculate probe positions. From these positions and
the information which probes has been executed (e.g. read from exec
files) all metrics are interfered: Instructions, branches, probes, lines
etc. But this works only for the exact same class file. If you do
analysis on a different class file (different ordering of methods,
additional/loss methods, extra/less code in methods) you will end-up
with different probes. Thereefore JaCoCo requires the exact same class
file at analysis as at runtime. This is guaranteed by the hash.
Cheers,
-marc
>>> <
https://code.google.com/p/powermock/issues/detail?id=402 [1]> and
>> here
>>> <
https://github.com/jacoco/eclemma/issues/15 [2]> and in many
>> other places.
>>> Just as a reminder, "JaCoCo uses a hashcode of the class
>> definition for
>>> class identity" that's why it can't determine coverage on classes
>> which
>>> were instrumented by PowerMock.
>>>
>>> I also know, that the official answer is "This is a known
>> limitation we
>>> can't currently do anything about". Pardon for being persistent,
>> but
>>> maybe I can give you a hand in fixing this problem?
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>
>>> Groups "JaCoCo and EclEmma Users" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>> send
>>> an email to
jacoco+un...@googlegroups.com.
>>> For more options, visit
https://groups.google.com/groups/opt_out
>> [3].
> [4].
>
>
>
> Links:
> ------
> [1]
https://code.google.com/p/powermock/issues/detail?id=402
> [2]
https://github.com/jacoco/eclemma/issues/15
> [3]
https://groups.google.com/groups/opt_out
> [4]
https://groups.google.com/groups/opt_out