"GenericArrayTypeImpl cannot be cast to Class" when MockUp<GENERIC_AS_SUPER> #347

YangZhong opened this Issue Sep 28, 2016 · 4 comments


None yet

2 participants


Please provide the following information:

  • Version of JMockit that was used:
    1.28 1.27 1.26 1.25
    Java "1.8.0_102"
  • Description of the problem or enhancement request:
    "java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl cannot be cast to java.lang.Class" when MockUp<GENERIC_AS_SUPER>.
    That's a regression because 1.24 works perfectly.

public class GENERIC_AS_SUPER extends SUPER<GENERIC>
public class TEST extends Assert

@BeforeClass  //  jUnit 4.12
static public void SET_UP() throws Exception
    new MockUp<GENERIC_AS_SUPER>()
        void $init()



I cannot reproduce the problem. How are the "SUPER" and "GENERIC" types defined?

YangZhong commented Sep 28, 2016 edited

Thanks to Rogério for trying to reproduce. A SUPER<GENERIC> example is HashMap<Object,Collection<Object>[][]>. In order to simplify regression reproducing & any fix verification, here's a simplified Test Case and could you remove "could not reproduce" tag please:

public class Regression {
  @Test  //  jUnit 4.12
  public void works1_24() {
    new MockUp<HashMap<Object,Collection<Object>[][]>>(){};
@rliesenfeld rliesenfeld added bug and removed could not reproduce labels Sep 28, 2016
@rliesenfeld rliesenfeld self-assigned this Sep 28, 2016


Note there is no need to use the full generic type declaration in the new MockUp<T>() call.
Writing new MockUp<HashMap<?, ?>>() works (that said, HashMap should never be mocked/faked).


Thank you Rogério actually.

Just want to clarify some potential misunderstanding. We do not use the full generic type declaration in the new MockUp<T>() call. We do MockUp<GENERIC_AS_SUPER> as mentioned above. GENERIC_AS_SUPER is our own class we have to mock in only some of our Test Cases.

Also as commented above, above Test Case is purposely simplified for regression reproducing & any fix verification. While ourselves do not have any Test Case mocking/faking HashMap (yet), we don't choose the sides of HashMap ever needs mocking/faking vs. should never.

@rliesenfeld rliesenfeld added a commit that closed this issue Oct 2, 2016
@rliesenfeld rliesenfeld Fixed bug in the extraction of type information from a multi-dimensio…
…nal generic array which is being mocked or faked; closes #347.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment