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

Can't run tests with Java 9 and above #1541

Closed
doom369 opened this issue Apr 29, 2018 · 8 comments
Closed

Can't run tests with Java 9 and above #1541

doom369 opened this issue Apr 29, 2018 · 8 comments

Comments

@doom369
Copy link
Contributor

doom369 commented Apr 29, 2018

Spotted issues so far:

org.testng.TestNGException: 
An error occurred while instantiating class org.asynchttpclient.request.body.multipart.MultipartBodyTest: javax/activation/MimetypesFileTypeMap
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:435)
	at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336)
	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
	at org.testng.TestClass.getInstances(TestClass.java:95)
	at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:81)
	at org.testng.TestClass.init(TestClass.java:73)
	at org.testng.TestClass.<init>(TestClass.java:38)
	at org.testng.TestRunner.initMethods(TestRunner.java:389)
	at org.testng.TestRunner.init(TestRunner.java:271)
	at org.testng.TestRunner.init(TestRunner.java:241)
	at org.testng.TestRunner.<init>(TestRunner.java:167)
	at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:663)
	at org.testng.SuiteRunner.init(SuiteRunner.java:260)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:198)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1271)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1249)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1107)
	at org.testng.TestNG.runSuites(TestNG.java:1028)
	at org.testng.TestNG.run(TestNG.java:996)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.NoClassDefFoundError: javax/activation/MimetypesFileTypeMap
	at org.asynchttpclient.request.body.multipart.FileLikePart.<clinit>(FileLikePart.java:31)
	at org.asynchttpclient.request.body.multipart.MultipartBodyTest.<clinit>(MultipartBodyTest.java:43)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at org.testng.internal.ObjectFactoryImpl.newInstance(ObjectFactoryImpl.java:24)
	at org.powermock.modules.testng.PowerMockObjectFactory.newInstance(PowerMockObjectFactory.java:46)
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423)
	... 21 more
Caused by: java.lang.ClassNotFoundException: javax.activation.MimetypesFileTypeMap
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	... 30 more

In order to fix that you need to add:

      <dependency>
        <groupId>com.sun.activation</groupId>
        <artifactId>javax.activation</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
      </dependency>
org.testng.TestNGException: 
An error occurred while instantiating class org.asynchttpclient.handler.resumable.ResumableAsyncHandlerTest: Cannot create a new instance of test class class org.asynchttpclient.handler.resumable.ResumableAsyncHandlerTest
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:435)
	at org.testng.internal.ClassHelper.createInstance(ClassHelper.java:336)
	at org.testng.internal.ClassImpl.getDefaultInstance(ClassImpl.java:125)
	at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:190)
	at org.testng.TestClass.getInstances(TestClass.java:95)
	at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:81)
	at org.testng.TestClass.init(TestClass.java:73)
	at org.testng.TestClass.<init>(TestClass.java:38)
	at org.testng.TestRunner.initMethods(TestRunner.java:389)
	at org.testng.TestRunner.init(TestRunner.java:271)
	at org.testng.TestRunner.init(TestRunner.java:241)
	at org.testng.TestRunner.<init>(TestRunner.java:167)
	at org.testng.SuiteRunner$DefaultTestRunnerFactory.newTestRunner(SuiteRunner.java:663)
	at org.testng.SuiteRunner.init(SuiteRunner.java:260)
	at org.testng.SuiteRunner.<init>(SuiteRunner.java:198)
	at org.testng.TestNG.createSuiteRunner(TestNG.java:1271)
	at org.testng.TestNG.createSuiteRunners(TestNG.java:1249)
	at org.testng.TestNG.runSuitesLocally(TestNG.java:1107)
	at org.testng.TestNG.runSuites(TestNG.java:1028)
	at org.testng.TestNG.run(TestNG.java:996)
	at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
	at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: java.lang.RuntimeException: Cannot create a new instance of test class class org.asynchttpclient.handler.resumable.ResumableAsyncHandlerTest
	at org.powermock.modules.testng.internal.TestClassInstanceFactory.create(TestClassInstanceFactory.java:59)
	at org.powermock.modules.testng.internal.PowerMockClassloaderObjectFactory.newInstance(PowerMockClassloaderObjectFactory.java:46)
	at org.powermock.modules.testng.PowerMockObjectFactory.newInstance(PowerMockObjectFactory.java:43)
	at org.testng.internal.ClassHelper.createInstance1(ClassHelper.java:423)
	... 21 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
	at org.powermock.modules.testng.internal.TestClassInstanceFactory.create(TestClassInstanceFactory.java:51)
	... 24 more
Caused by: org.objenesis.ObjenesisException: java.lang.reflect.InvocationTargetException
	at org.objenesis.instantiator.sun.SunReflectionFactoryHelper.newConstructorForSerialization(SunReflectionFactoryHelper.java:55)
	at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflectionFactoryInstantiator.java:38)
	at org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:58)
	at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:91)
	at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:250)
	at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)
	at org.powermock.modules.testng.PowerMockTestCase.<init>(PowerMockTestCase.java:51)
	at org.asynchttpclient.handler.resumable.ResumableAsyncHandlerTest.<init>(ResumableAsyncHandlerTest.java:43)
	... 29 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.objenesis.instantiator.sun.SunReflectionFactoryHelper.newConstructorForSerialization(SunReflectionFactoryHelper.java:45)
	... 36 more
Caused by: java.lang.IllegalAccessError: class jdk.internal.reflect.ConstructorAccessorImpl loaded by org/powermock/core/classloader/MockClassLoader cannot access jdk/internal/reflect superclass jdk.internal.reflect.MagicAccessorImpl
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1009)
	at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:250)
	at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:194)
	at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:77)
	at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1009)
	at org.powermock.core.classloader.MockClassLoader.loadUnmockedClass(MockClassLoader.java:250)
	at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:194)
	at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:77)
	at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	at java.base/jdk.internal.misc.Unsafe.defineClass0(Native Method)
	at java.base/jdk.internal.misc.Unsafe.defineClass(Unsafe.java:1192)
	at java.base/jdk.internal.reflect.ClassDefiner.defineClass(ClassDefiner.java:63)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:400)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator.generateSerializationConstructor(MethodAccessorGenerator.java:112)
	at java.base/jdk.internal.reflect.ReflectionFactory.generateConstructor(ReflectionFactory.java:434)
	at java.base/jdk.internal.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:404)
	at jdk.unsupported/sun.reflect.ReflectionFactory.newConstructorForSerialization(ReflectionFactory.java:103)
	... 41 more

Fix requires either update powermock dependency to the latest version (2.0.0.beta5) or test should be changed a bit in order to remove it and use only latest mockito.

@slandelle
Copy link
Contributor

@doom369 MimetypesFileTypeMap is already in JDK, there's no reason to add javax.activation dependency. Is this some Jigsaw crap?

@doom369
Copy link
Contributor Author

doom369 commented Apr 29, 2018

@slandelle yes. it is in JDK, however, it is now in the separate module that will be removed soon (in java 11 I believe), so in order to get it in Java9 and above you need either to add "--add-modules java.activation" during jvm start or add above dependency.

Adding dependency is recommended way, as those classes will be removed from JDK.
https://stackoverflow.com/questions/46493613/what-is-the-replacement-for-javax-activation-package-in-java-9

@slandelle
Copy link
Contributor

fixed

Note that AHC is not intended to be built with JKD9+ atm as the binary wouldn't be compatible with JDK8 (due to new ByteBuffer#flip).
Also note that I have zero interest in JDK9+ module path so compatibility will have to come from contributions.

@doom369
Copy link
Contributor Author

doom369 commented Apr 29, 2018

(due to new ByteBuffer#flip)

It is actually could be fixed very easily too:

((Buffer) byteBuf).flip();

I use flip() as well and this hack works perfectly both for JDK8 and JDK9 (and JDK10 as well).

@slandelle
Copy link
Contributor

Yeah, I know, but that means uglifying code everywhere. Netty has the same issue.
From he polls I did, Java 9 has very very little traction. Maybe once Java 11 is out and Java 8 will reach EOL, things will change. Then, I might target Java 11 (don't plan to cross build either).

@doom369
Copy link
Contributor Author

doom369 commented Apr 29, 2018

Agree. There are still a lot of people who use 1.5 :). So understandable.

@doom369
Copy link
Contributor Author

doom369 commented Apr 29, 2018

By the way, this ticket is not yet resolved, as powermock uses removed from JDK API :). I tried to remove it but got some tests failed. But I have a feeling they were failing before.

@slandelle
Copy link
Contributor

Nah, I removed Powermock in dedicated commit and upgraded Mockito.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants