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

Defining classes in Java 10 EA build fails because it complains about Java version number #370

Closed
uschindler opened this Issue Nov 3, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@uschindler

uschindler commented Nov 3, 2017

When using Mockito to run Mocking test under the today-released Java 10 EA build 29, it fails when tyring to define the class:

   [junit4]    > Underlying exception : java.lang.UnsupportedOperationException: Cannot define class using reflection
   [junit4]    > 	at __randomizedtesting.SeedInfo.seed([393EAB7FEDECCD7D:6281250A3A6CAD54]:0)
   [junit4]    > 	at org.apache.solr.cloud.AssignTest.testAssignNode(AssignTest.java:65)
   [junit4]    > 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   [junit4]    > 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   [junit4]    > 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   [junit4]    > 	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
   [junit4]    > 	at java.base/java.lang.Thread.run(Thread.java:844)
   [junit4]    > Caused by: java.lang.UnsupportedOperationException: Cannot define class using reflection
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Unavailable.defineClass(ClassInjector.java:819)
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:183)
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:187)
   [junit4]    > 	at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
   [junit4]    > 	at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4352)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:94)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:35)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:32)
   [junit4]    > 	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
   [junit4]    > 	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
   [junit4]    > 	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
   [junit4]    > 	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:30)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:26)
   [junit4]    > 	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
   [junit4]    > 	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65)
   [junit4]    > 	at org.mockito.Mockito.mock(Mockito.java:1681)
   [junit4]    > 	at org.mockito.Mockito.mock(Mockito.java:1594)
   [junit4]    > 	... 39 more
   [junit4]    > Caused by: java.lang.IllegalArgumentException: Unknown Java version: 10
   [junit4]    > 	at net.bytebuddy.ClassFileVersion.ofJavaVersion(ClassFileVersion.java:135)
   [junit4]    > 	at net.bytebuddy.ClassFileVersion$VersionLocator$ForJava9CapableVm.locate(ClassFileVersion.java:337)
   [junit4]    > 	at net.bytebuddy.ClassFileVersion.ofThisVm(ClassFileVersion.java:147)
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:299)
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$CreationAction.run(ClassInjector.java:288)
   [junit4]    > 	at java.base/java.security.AccessController.doPrivileged(Native Method)
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.<clinit>(ClassInjector.java:68)
   [junit4]    > 	at net.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:184)
   [junit4]    > 	at net.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
   [junit4]    > 	at net.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4352)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:94)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:35)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:32)
   [junit4]    > 	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:138)
   [junit4]    > 	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:346)
   [junit4]    > 	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:161)
   [junit4]    > 	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:355)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:30)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
   [junit4]    > 	at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:26)
   [junit4]    > 	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
   [junit4]    > 	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65)
   [junit4]    > 	at org.mockito.Mockito.mock(Mockito.java:1681)
   [junit4]    > 	at org.mockito.Mockito.mock(Mockito.java:1594)
   [junit4]    > 	at org.apache.solr.handler.admin.TestCoreAdminApis.getCoreContainerMock(TestCoreAdminApis.java:73)
   [junit4]    > 	at org.apache.solr.handler.admin.TestCoreAdminApis.testCalls(TestCoreAdminApis.java:40)
   [junit4]    > 	... 38 more

This error message looks a bit too restrictive: I'd change the check to only require a minimum Java version (like 9) and then further try to mock instead of giving up.

This prevents us from testing Apache Solr with Java 10. We need to disable all mocking tests with Java 10. When changing the check to allow "10" as alias for "9" and rebuilding bytebuddy, everything works.

From Mark Reinhold's mail about the half-yearly release, the proposed spec also tells that the class file version is increased every half year, so the current way of doing those checks is tooo restrictive. There should be at least a "fallback" so it tries to do everything with latest known Java version first before giving up.

@uschindler

This comment has been minimized.

Show comment
Hide comment
@uschindler

uschindler Nov 4, 2017

This is the Solr workaround: https://issues.apache.org/jira/browse/SOLR-11606

We disable all tests using an assume if Mockito/ByteBuddy does not support the current runtime.

uschindler commented Nov 4, 2017

This is the Solr workaround: https://issues.apache.org/jira/browse/SOLR-11606

We disable all tests using an assume if Mockito/ByteBuddy does not support the current runtime.

simon04 pushed a commit to openstreetmap/josm that referenced this issue Nov 4, 2017

floscher pushed a commit to floscher/josm that referenced this issue Nov 5, 2017

sormuras referenced this issue in junit-team/junit5 Nov 6, 2017

@raphw raphw self-assigned this Nov 6, 2017

@raphw raphw added the bug label Nov 6, 2017

@raphw raphw added this to the 1.7.8 milestone Nov 6, 2017

@raphw

This comment has been minimized.

Show comment
Hide comment
@raphw

raphw Nov 6, 2017

Owner

Fixed on master and made more robust for future version increments. Will be fixed with the next release.

Owner

raphw commented Nov 6, 2017

Fixed on master and made more robust for future version increments. Will be fixed with the next release.

@raphw raphw closed this Nov 7, 2017

@raphw

This comment has been minimized.

Show comment
Hide comment
@raphw

raphw Nov 7, 2017

Owner

Bugfix is released.

Owner

raphw commented Nov 7, 2017

Bugfix is released.

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