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

SoftAssertions java.lang.IllegalArgumentException: Could not create type #1322

Closed
tommyalatalo opened this issue Sep 11, 2018 · 5 comments
Closed

Comments

@tommyalatalo
Copy link

tommyalatalo commented Sep 11, 2018

I keep getting an IllegalArgumentException when trying to use SoftAssertions, I've tried using several of the libraries provided:

org.assertj.core.api.JUnitJupiterSoftAssertions
org.assertj.core.api.SoftAssertions
org.assertj.core.api.Java6SoftAssertions,
org.assertj.core.api.Java6UnitSoftAssertions

no matter of how I state the assertions in the code (using lambda, JUnit @rule, JUnit5 @RegisterExtension etc. I keep getting the attached error.

I'm trying to do this on Android, running 8.0 and JUnit 5 with the dependency set in my gradle build to;
androidTestImplementation "org.assertj:assertj-core:3.11.1"

My test class in short

import static org.assertj.core.api.Assertions.assertThat;

public class tester {
@RegisterExtension
    public final JUnitJupiterSoftAssertions softly = new JUnitJupiterSoftAssertions();

Test
    public void test1() {
        softly.assertThat(true).as("Soft assertion is working: ").isTrue();
}

Above code is of course truncated, but all my efforts have resulted in the below error.
I'm wondering if I'm doing something wrong as there are no open issues for this that I can find.

java.lang.IllegalArgumentException: Could not create type
at org.assertj.core.internal.bytebuddy.TypeCache.findOrInsert(TypeCache.java:139)
at org.assertj.core.internal.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:344)
at org.assertj.core.api.SoftProxies.createSoftAssertionProxyClass(SoftProxies.java:113)
at org.assertj.core.api.SoftProxies.createSoftAssertionProxy(SoftProxies.java:99)
at org.assertj.core.api.AbstractSoftAssertions.proxy(AbstractSoftAssertions.java:36)
at org.assertj.core.api.Java6AbstractStandardSoftAssertions.assertThat(Java6AbstractStandardSoftAssertions.java:83)
at se.mobilaris.mmi.onboard.logging.LoggerTest.testLoggerLocal(tester.java:115)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:513)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:170)
at org.junit.jupiter.engine.descriptor.-$$Lambda$TestMethodTestDescriptor$MyLkNeNS_7-rEVMQf9yz-b1AJ98.execute(Unknown Source:6)
at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:166)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:113)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:113)
at org.junit.platform.engine.support.hierarchical.-$$Lambda$HierarchicalTestExecutor$NodeExecutor$9odrcTqRVn1-4NOsM79SRrXwBXg.execute(Unknown Source:4)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
at org.junit.platform.engine.support.hierarchical.-$$Lambda$HierarchicalTestExecutor$NodeExecutor$KXxnxDYB3VpYXO74B3geeRSeGVk.accept(Unknown Source:6)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:148)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:235)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:419)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
at org.junit.platform.engine.support.hierarchical.-$$Lambda$HierarchicalTestExecutor$NodeExecutor$9odrcTqRVn1-4NOsM79SRrXwBXg.execute(Unknown Source:4)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
at org.junit.platform.engine.support.hierarchical.-$$Lambda$HierarchicalTestExecutor$NodeExecutor$KXxnxDYB3VpYXO74B3geeRSeGVk.accept(Unknown Source:6)
at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:176)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:148)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:235)
at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:419)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
at org.junit.platform.engine.support.hierarchical.-$$Lambda$HierarchicalTestExecutor$NodeExecutor$9odrcTqRVn1-4NOsM79SRrXwBXg.execute(Unknown Source:4)
at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at org.junit.platform.runner.JUnitPlatform.run(JUnitPlatform.java:139)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2106)
Caused by: java.lang.IllegalStateException: Error invoking java.lang.ClassLoader#defineClass
at org.assertj.core.internal.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Direct.defineClass(ClassInjector.java:521)
at org.assertj.core.internal.bytebuddy.dynamic.loading.ClassInjector$UsingReflection.inject(ClassInjector.java:184)
at org.assertj.core.internal.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default$InjectionDispatcher.load(ClassLoadingStrategy.java:205)
at org.assertj.core.internal.bytebuddy.dynamic.loading.ClassLoadingStrategy$Default.load(ClassLoadingStrategy.java:126)
at org.assertj.core.internal.bytebuddy.dynamic.TypeResolutionStrategy$Passive.initialize(TypeResolutionStrategy.java:79)
at org.assertj.core.internal.bytebuddy.dynamic.DynamicType$Default$Unloaded.load(DynamicType.java:4991)
at org.assertj.core.api.SoftProxies.generateProxyClass(SoftProxies.java:160)
at org.assertj.core.api.SoftProxies.lambda$createSoftAssertionProxyClass$0(SoftProxies.java:113)
at org.assertj.core.api.-$$Lambda$SoftProxies$HCd5s6BUGA5SWHvX2FS-7U20akk.call(Unknown Source:2)
at org.assertj.core.internal.bytebuddy.TypeCache.findOrInsert(TypeCache.java:137)
... 73 more
Caused by: java.lang.UnsupportedOperationException: can't load this type of class file
at java.lang.ClassLoader.defineClass(ClassLoader.java:591)
at java.lang.reflect.Method.invoke(Native Method)
at org.assertj.core.internal.bytebuddy.dynamic.loading.ClassInjector$UsingReflection$Dispatcher$Direct.defineClass(ClassInjector.java:517)
... 82 more

Tests ran to completion.```

@PascalSchumacher
Copy link
Member

Hi,

for SoftAssertions AssertJ uses https://github.com/raphw/byte-buddy

If I understand http://bytebuddy.net/#/tutorial ("Loading classes in Android applications" section) correctly, (normal) Byte Buddy does not work on Android.

Sorry!

@tommyalatalo
Copy link
Author

tommyalatalo commented Sep 12, 2018

Hi,

for SoftAssertions AssertJ uses https://github.com/raphw/byte-buddy

If I understand http://bytebuddy.net/#/tutorial ("Loading classes in Android applications" section) correctly, (normal) Byte Buddy does not work on Android.

Sorry!

Then this should be clear in the documentation, I spent hours on this yesterday and there was no mention of incompatibility with Android, on the contrary there is a section on the AssertJ site on how it works with Android: http://joel-costigliola.github.io/assertj/assertj-core.html#android
You should either update the section on android and put in a mention for SoftAssertions or hopefully fix the problem, preferrably the latter because soft assertions seem like a great tool!

@joel-costigliola
Copy link
Member

Fair enough, this should clear in the doc.

@joel-costigliola
Copy link
Member

@aartiPl
Copy link

aartiPl commented Apr 26, 2019

There is a version of ByteBuddy for Android: byte-buddy-android. Couldn't it be used instead of regular bytebuddy for AssertJ? Lack of SoftAssertions is really painful for Android. I have to wrap normal assertions, catch errors and then at the end present user results. Please check if Android version of ByteBuddy can be applied for AssertJ.

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

4 participants