jMock

Mocking a static nested class causes a net.sf.cglib.core.CodeGenerationException to be thrown.

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.2.0
  • Fix Version/s: None
  • Component/s: JMock 1.x.x Library
  • Labels:
    None
  • Number of attachments :
    0

Description

In some code that I have inherited I have a class with a static nested class. In the past (jMock 1.1.0) I was able to successfully mock this static nested class. After upgrading to jMock 1.2.0, this no longer works. I end up getting the following exception:
net.sf.cglib.core.CodeGenerationException: java.lang.IllegalAccessError-->tried to access method org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6.CGLIB$setPageNumber$6(I)V from class org.jmock.codegen.org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6$$FastClassByCGLIB$$e9f65fd5
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220)
at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:636)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:304)
at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:63)
at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:46)
at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:35)
at org.jmock.cglib.MockObjectTestCase.newCoreMock(MockObjectTestCase.java:33)
at org.jmock.MockObjectTestCase.mock(MockObjectTestCase.java:67)
at org.jmock.MockObjectTestCase.mock(MockObjectTestCase.java:55)
at com.mycompany.core.persistence.hbm.HBMBaseDAOTest.testLimitResultSet(HBMBaseDAOTest.java:117)
Caused by: java.lang.IllegalAccessError: tried to access method org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6.CGLIB$setPageNumber$6(I)V from class org.jmock.codegen.org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6$$FastClassByCGLIB$$e9f65fd5
at org.jmock.codegen.org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6$$FastClassByCGLIB$$e9f65fd5.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
at org.jmock.cglib.CGLIBCoreMock.intercept(CGLIBCoreMock.java:79)
at org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6.setPageNumber(<generated>)
at com.mycompany.core.util.DataPage$DataPageDefinition.<init>(DataPage.java:280)
at com.mycompany.core.util.DataPage$DataPageDefinition.<init>(DataPage.java:267)
at org.jmock.codegen.com.mycompany.core.util.DataPage$DataPageDefinition$$EnhancerByCGLIB$$3417fee6.<init>(<generated>)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228)
... 58 more

Research led me to the following:
http://www.gg3721.com/list/50/44427.html
and the followup
http://www.gg3721.com/list/50/44774.html

Activity

Hide
Ryan C. Payne added a comment -

Is there any workaround to get this to work again, short of rolling back to jMock 1.1.0 or breaking out the static nested class into it's own file?

Show
Ryan C. Payne added a comment - Is there any workaround to get this to work again, short of rolling back to jMock 1.1.0 or breaking out the static nested class into it's own file?
Hide
Nat Pryce added a comment -

Is the static nested class public?

If not, can you work around the problem by making it public?

Show
Nat Pryce added a comment - Is the static nested class public? If not, can you work around the problem by making it public?
Hide
Ryan C. Payne added a comment -

Yes, the static nested class is indeed public.

Show
Ryan C. Payne added a comment - Yes, the static nested class is indeed public.
Hide
Nat Pryce added a comment -

If you could give us a small, self-contained JUnit test that demonstrates the problem, that would be a great help in tracking this down.

Show
Nat Pryce added a comment - If you could give us a small, self-contained JUnit test that demonstrates the problem, that would be a great help in tracking this down.
Hide
Ryan C. Payne added a comment -

Sure thing. I will whip that up this afternoon and attach it to the JIRA.

Show
Ryan C. Payne added a comment - Sure thing. I will whip that up this afternoon and attach it to the JIRA.
Hide
Nat Pryce added a comment -

Great! Thanks.

Show
Nat Pryce added a comment - Great! Thanks.
Hide
Ryan Hoegg added a comment -

Did you ever make the small, self-contained JUnit test?

Show
Ryan Hoegg added a comment - Did you ever make the small, self-contained JUnit test?
Hide
Duncan Mac-Vicar P. added a comment -

We are seeing this problem when building a rpm package of jmock-1.2.0. The jmock testsuite fails for ppc and s390, which means IBM's JVM. I could reproduce it then on i586 by forcing IBM Java to be installed instead of openJDK.

The testsuite fails on jmock-1.2.0/src/atest/jmock/cglib/MockConcreteClassAcceptanceTest.java

[junit] Testsuite: atest.jmock.cglib.ErrorDetectionAcceptanceTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.014 sec
[junit]
[junit] Testsuite: atest.jmock.cglib.MockConcreteClassAcceptanceTest
[junit] Tests run: 4, Failures: 0, Errors: 1, Time elapsed: 0.275 sec
[junit]
[junit] Testcase: testCanMockClassesWithComplexConstructors(atest.jmock.cglib.MockConcreteClassAcceptanceTest): Caused an ERROR
[junit] java.lang.IllegalAccessError-->org/jmock/codegen/atest/jmock/cglib/MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.CGLIB$mockedMethod$0()Ljava/lang/String;
[junit] net.sf.cglib.core.CodeGenerationException: java.lang.IllegalAccessError-->org/jmock/codegen/atest/jmock/cglib/MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.CGLIB$mockedMethod$0()Ljava/lang/String;
[junit] at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235)
[junit] at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220)
[junit] at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:636)
[junit] at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
[junit] at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225)
[junit] at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
[junit] at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:304)
[junit] at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:63)
[junit] at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:46)
[junit] at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:35)
[junit] at org.jmock.cglib.MockObjectTestCase.newCoreMock(MockObjectTestCase.java:33)
[junit] at org.jmock.MockObjectTestCase.mock(MockObjectTestCase.java:67)
[junit] at atest.jmock.cglib.MockConcreteClassAcceptanceTest.testCanMockClassesWithComplexConstructors(MockConcreteClassAcceptanceTest.java:71)
[junit] at org.jmock.core.VerifyingTestCase.runBare(VerifyingTestCase.java:39)
[junit] Caused by: java.lang.IllegalAccessError: org/jmock/codegen/atest/jmock/cglib/MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.CGLIB$mockedMethod$0()Ljava/lang/String;
[junit] at org.jmock.codegen.org.jmock.codegen.atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146$$FastClassByCGLIB$$64c65b38.invoke(<generated>)
[junit] at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
[junit] at org.jmock.cglib.CGLIBCoreMock.intercept(CGLIBCoreMock.java:79)
[junit] at org.jmock.codegen.atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.mockedMethod(<generated>)
[junit] at atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor.<init>(MockConcreteClassAcceptanceTest.java:63)
[junit] at org.jmock.codegen.atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.<init>(<generated>)
[junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
[junit] at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228)
[junit]
[junit]

Show
Duncan Mac-Vicar P. added a comment - We are seeing this problem when building a rpm package of jmock-1.2.0. The jmock testsuite fails for ppc and s390, which means IBM's JVM. I could reproduce it then on i586 by forcing IBM Java to be installed instead of openJDK. The testsuite fails on jmock-1.2.0/src/atest/jmock/cglib/MockConcreteClassAcceptanceTest.java [junit] Testsuite: atest.jmock.cglib.ErrorDetectionAcceptanceTest [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.014 sec [junit] [junit] Testsuite: atest.jmock.cglib.MockConcreteClassAcceptanceTest [junit] Tests run: 4, Failures: 0, Errors: 1, Time elapsed: 0.275 sec [junit] [junit] Testcase: testCanMockClassesWithComplexConstructors(atest.jmock.cglib.MockConcreteClassAcceptanceTest): Caused an ERROR [junit] java.lang.IllegalAccessError-->org/jmock/codegen/atest/jmock/cglib/MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.CGLIB$mockedMethod$0()Ljava/lang/String; [junit] net.sf.cglib.core.CodeGenerationException: java.lang.IllegalAccessError-->org/jmock/codegen/atest/jmock/cglib/MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.CGLIB$mockedMethod$0()Ljava/lang/String; [junit] at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:235) [junit] at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:220) [junit] at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:636) [junit] at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538) [junit] at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:225) [junit] at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) [junit] at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:304) [junit] at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:63) [junit] at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:46) [junit] at org.jmock.cglib.CGLIBCoreMock.<init>(CGLIBCoreMock.java:35) [junit] at org.jmock.cglib.MockObjectTestCase.newCoreMock(MockObjectTestCase.java:33) [junit] at org.jmock.MockObjectTestCase.mock(MockObjectTestCase.java:67) [junit] at atest.jmock.cglib.MockConcreteClassAcceptanceTest.testCanMockClassesWithComplexConstructors(MockConcreteClassAcceptanceTest.java:71) [junit] at org.jmock.core.VerifyingTestCase.runBare(VerifyingTestCase.java:39) [junit] Caused by: java.lang.IllegalAccessError: org/jmock/codegen/atest/jmock/cglib/MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.CGLIB$mockedMethod$0()Ljava/lang/String; [junit] at org.jmock.codegen.org.jmock.codegen.atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146$$FastClassByCGLIB$$64c65b38.invoke(<generated>) [junit] at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167) [junit] at org.jmock.cglib.CGLIBCoreMock.intercept(CGLIBCoreMock.java:79) [junit] at org.jmock.codegen.atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.mockedMethod(<generated>) [junit] at atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor.<init>(MockConcreteClassAcceptanceTest.java:63) [junit] at org.jmock.codegen.atest.jmock.cglib.MockConcreteClassAcceptanceTest$ClassWithComplexConstructor$$EnhancerByCGLIB$$5b092146.<init>(<generated>) [junit] at java.lang.reflect.Constructor.newInstance(Constructor.java:527) [junit] at net.sf.cglib.core.ReflectUtils.newInstance(ReflectUtils.java:228) [junit] [junit]

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated: