Skip to content

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

@eugoss

Description

@eugoss
  • 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]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions