Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking fails for generic classes with NoSuchMethodException on $Proxy objects #210

hamid-nazari opened this issue Sep 27, 2015 · 0 comments


Copy link

@hamid-nazari hamid-nazari commented Sep 27, 2015

I recently updated JMockit from 1.16 to 1.19 and ran all test suites I had prepared for my previously reported issues and all passed correctly.
But yesterday one of my developers reported a failure on her old tests cases which used to pass. Wondering what might have went wrong, I finally restored JMockit 1.16 to find out that the test pass now.
This was very weird exception to spot and it was very hard to reproduce in another test case. I had to work on it for few hours before being able to create such combination with simplified version of our complex hierarchy of generic objects.

I also check with other versions and found out that the issue manifests itself from update 1.17 onward.

Here is the test case

import static org.testng.Assert.assertEquals;

import org.testng.annotations.Test;

import mockit.Injectable;
import mockit.NonStrictExpectations;

public class JMockitGenericsFailureTests
    public interface Identifier

    public static class ModuleID implements Identifier
        public static final ModuleID    ID1 = new ModuleID();
        public static final ModuleID    ID2 = new ModuleID();
        public static final ModuleID    ID3 = new ModuleID();

    public interface Identifiable<ID_TYPE extends Identifier>
        ID_TYPE getID();

    public interface IRegistrar<SUB_ITEM_TYPE extends Identifiable<ID_TYPE>, ID_TYPE extends Identifier>
        SUB_ITEM_TYPE getSubItem(ID_TYPE subItemID);

    public interface IModule extends Identifiable<ModuleID>


    public interface IApplicationStub<UTILITY_TYPE extends Identifiable<ModuleID>>
        IRegistrar<UTILITY_TYPE, ModuleID> getModuleRegistry();

    public interface IModularApplication extends IApplicationStub<IModule>


    private IModularApplication application;

    private IModule testModule1;
    private IModule testModule2;

    public void genericsFailure_proxy_NoSuchMethod()
        testModule1 = new IModule()

            public ModuleID getID()
                return ModuleID.ID1;

        new NonStrictExpectations()
                result = testModule1;
                result = testModule2;
                result = null;

        assertEquals(application.getModuleRegistry().getSubItem(ModuleID.ID1), testModule1);
        assertEquals(application.getModuleRegistry().getSubItem(ModuleID.ID2), testModule2);

Here is the exception stack trace of running it with 1.17+:

java.lang.RuntimeException: java.lang.InstantiationException: com.sun.proxy.$Proxy6
    at JMockitGenericsFailureTests$2.<init>(
    at JMockitGenericsFailureTests.genericsFailure_proxy_NoSuchMethod(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(
Caused by: java.lang.InstantiationException: com.sun.proxy.$Proxy6
    at java.lang.Class.newInstance(
    ... 4 more
Caused by: java.lang.NoSuchMethodException: com.sun.proxy.$Proxy6.<init>()
    at java.lang.Class.getConstructor0(
    at java.lang.Class.newInstance(
    ... 4 more

Our test environment:

  • JDK 1.8u60
  • TestNG 6.9.5 on Eclipse
  • JMockit 1.16, 1.17, 1.18 and 1.19
@rliesenfeld rliesenfeld added the bug label Sep 28, 2015
@rliesenfeld rliesenfeld self-assigned this Sep 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.