MemoryClassLoader and LinkageErrors related to loading in Classes

20 views
Skip to first unread message

wwaylo...@gmail.com

unread,
Mar 11, 2018, 10:29:22 PM3/11/18
to JaCoCo and EclEmma Users
Hi,

I followed the CoreTutorial example class at http://www.jacoco.org/jacoco/trunk/doc/examples/java/CoreTutorial.java to understand how to incorporate Jacoco into a project.

However, I am facing java.lang.LinkageError problem that is related to the MemoryClassLoader class that is used.

Specifically, I have two classes, MyClass and MySubClass where MySubClass extends MyClass. I instrument both classes so that I can get coverage information related to each. I've found that if I instrument MySubClass first, MemoryClassLoader will call defineClass with the instrumented bytes for MySubClass. However, in doing so, MyClass, which is the parent class, also gets loaded in by the parent class loader. Thus, when I next instrument and load MyClass, I receive the java.lang.LinkageError which claims that there is already a definition of MyClass that has been loaded by a ClassLoader. The problem here is that the initial version of MyClass that was loaded in was not instrumented.

If I load in classes in the reverse order, this issue does not arise.

I've tried something a bit different here: https://github.com/huangwaylon/randoop/blob/bloodhound/src/main/java/randoop/main/MemoryClassLoader.java by immediately attempting to instrument the parent class upon a recursive call to loadClass. However, this isn't entirely working due to reasons I haven't figured out yet. I am observing that the coverage information for both classes are not changing if I use this faulty approach.

My question overall is, how can I instrument and load in classes that are related to each other in a parent, child relationship such that the behavior isn't affected by the order? Am I able to replace the definition of a class? Another problem seems to be super.load which would be the parent ClassLoader to MemoryClassLoader which I don't have control over.


Evgeny Mandrikov

unread,
Mar 12, 2018, 10:39:52 PM3/12/18
to JaCoCo and EclEmma Users
Hi,

Seems that this was answered already in https://stackoverflow.com/a/49232726/244993

In future for cross posts please consider providing cross link and notification that answer was already given. Thank you for your understanding.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages