@Capturing causes java.lang.LinkageError in JMockit 1.23 (works in earlier versions) #280

Closed
eugoss opened this Issue May 23, 2016 · 3 comments

Projects

None yet

2 participants

@eugoss
eugoss commented May 23, 2016 edited
  • Version of JMockit that was used: 1.23
    It works in versions <= 1.22 . It's broken only in 1.23
  • Description of the problem or enhancement request:

A LinkageError (attempted duplicate class definition) happened to me several times, under different circumstances, when I was adding tests to our production code, trying to mock interfaces using @Capturing.

Although I cannot bring up the production code here, I created a simplified test instead, which is more or less similar to what I have in real tests. The test works fine with @Mocked, but fails with @Capturing. It's taken from my sample repository, where I used JMockit+JUnit4 to test code based on ICU4J library. But, certainly, it fails not only for ICU4J.

package com.keeprg.icu4test;

import mockit.Capturing;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class Test_Main
{
    @Test
    public void testCount(@Capturing final Log log)
    {
        assertEquals(3, Main.countCharacters("ABC", log));
    }
}

The interface Log is nowhere used in the underlying ICU4J classes, and the test fails with the following error:

java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): 
attempted  duplicate class definition for name:
"com/ibm/icu/impl/ICUResourceBundleImpl$ResourceTable"
at com.keeprg.icu4test.Test_Main.testCount(Test_Main.java:13)

Being run with -verbose:class it shows that it attempted to load com/ibm/icu/impl/ICUResourceBundleImpl$ResourceTable twice indeed:

[Loaded com.ibm.icu.impl.ICUResourceBundle from __VM_RedefineClasses__]
[Loaded com.ibm.icu.impl.ICUResourceBundleImpl from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.ICUResourceBundleImpl$ResourceContainer from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.ICUResourceBundleImpl$ResourceTable from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[Loaded com.ibm.icu.impl.ICUResourceBundleReader$Container from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.ICUResourceBundleReader$Table from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.ICUResourceBundleReader$Array from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.CacheBase from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.SoftCache from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.impl.ICUResourceBundle$2 from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
[Loaded com.ibm.icu.util.UResourceBundle from __VM_RedefineClasses__]
[Loaded java.util.ResourceBundle from __VM_RedefineClasses__]
[Loaded com.ibm.icu.impl.ICUResourceBundleImpl$ResourceTable from file:/home/eugene/.m2/repository/com/ibm/icu/icu4j/57.1/icu4j-57.1.jar]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@eugoss eugoss changed the title from @Capturing and java.lang.LinkageError to @Capturing causes java.lang.LinkageError in 1.23 May 24, 2016
@eugoss eugoss changed the title from @Capturing causes java.lang.LinkageError in 1.23 to @Capturing causes java.lang.LinkageError in JMockit 1.23 (works in earlier versions) May 24, 2016
@rliesenfeld rliesenfeld added the bug label May 24, 2016
@rliesenfeld rliesenfeld self-assigned this May 24, 2016
@rliesenfeld
Member

Fixed by a previous (and unrelated) commit.

Thanks for reporting.

@eugoss
eugoss commented May 24, 2016 edited

Awesome! Thanks a lot, Rogério! Yes, I've just noticed, there's 1.24 now,
but didn't have a chance to try it yet, since it's not in the maven repo
yet :)

@eugoss
eugoss commented May 24, 2016 edited

By the way, thanks for such an awesome framework! Very well designed and
the documentation is excellent. It's a pleasure to work with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment