vaadin / quarkus

An extension to Quarkus to support Vaadin Flow
Apache License 2.0
28 stars 3 forks source link

Executing tests (with maven clean install) on MacOs will generate JNA related Exception (java.lang.NoSuchMethodError: com/sun/jna/Memory.close()) #124

Open czp13 opened 1 year ago

czp13 commented 1 year ago

Executing tests with:

This will generate this exception:

[INFO] Running com.vaadin.flow.quarkus.it.SessionContextIT
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.001 s <<< FAILURE! - in com.vaadin.flow.quarkus.it.SessionContextIT
[ERROR] com.vaadin.flow.quarkus.it.SessionContextIT  Time elapsed: 0.001 s  <<< ERROR!
java.lang.NoClassDefFoundError: com.vaadin.flow.quarkus.it.AbstractCdiIT (initialization failure)
    at java.base/java.lang.J9VMInternals.initializationAlreadyFailed(J9VMInternals.java:172)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.junit.platform.commons.util.ReflectionUtils.newInstance(ReflectionUtils.java:550)
    at org.junit.jupiter.engine.execution.ConstructorInvocation.proceed(ConstructorInvocation.java:56)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:655)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.api.extension.InvocationInterceptor.interceptTestClassConstructor(InvocationInterceptor.java:73)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:77)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeTestClassConstructor(ClassBasedTestDescriptor.java:355)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateTestClass(ClassBasedTestDescriptor.java:302)
    at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:79)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.instantiateAndPostProcessTestInstance(ClassBasedTestDescriptor.java:280)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$4(ClassBasedTestDescriptor.java:272)
    at java.base/java.util.Optional.orElseGet(Optional.java:364)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$testInstancesProvider$5(ClassBasedTestDescriptor.java:271)
    at org.junit.jupiter.engine.execution.TestInstancesProvider.getTestInstances(TestInstancesProvider.java:31)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$before$2(ClassBasedTestDescriptor.java:197)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:196)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:80)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
    at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
    at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.execute(JUnitPlatformProvider.java:188)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:154)
    at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:128)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:428)
    at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
    at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:562)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:548)
Caused by: java.lang.NoClassDefFoundError: com.vaadin.flow.test.AbstractChromeIT (initialization failure)
    ... 69 more
Caused by: java.lang.NoSuchMethodError: com/sun/jna/Memory.close()V (loaded from file:/Users/pczuczor/.m2/repository/net/java/dev/jna/jna/5.8.0/jna-5.8.0.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@a506693f) called from class oshi.util.Util (loaded from file:/Users/pczuczor/.m2/repository/com/github/oshi/oshi-core/6.4.1/oshi-core-6.4.1.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@a506693f).
    at oshi.util.Util.freeMemory(Util.java:83)
    at oshi.jna.ByRef$CloseableSizeTByReference.close(ByRef.java:110)
    at oshi.util.platform.mac.SysctlUtil.sysctl(SysctlUtil.java:61)
    at oshi.util.platform.mac.SysctlUtil.sysctl(SysctlUtil.java:40)
    at oshi.hardware.platform.mac.MacCentralProcessor.initProcessorCounts(MacCentralProcessor.java:119)
    at oshi.hardware.common.AbstractCentralProcessor.<init>(AbstractCentralProcessor.java:65)
    at oshi.hardware.platform.mac.MacCentralProcessor.<init>(MacCentralProcessor.java:47)
    at oshi.hardware.platform.mac.MacHardwareAbstractionLayer.createProcessor(MacHardwareAbstractionLayer.java:42)
    at oshi.util.Memoizer$1.get(Memoizer.java:61)
    at oshi.hardware.common.AbstractHardwareAbstractionLayer.getProcessor(AbstractHardwareAbstractionLayer.java:48)
    at com.vaadin.pro.licensechecker.MachineId.getComputerId(MachineId.java:34)
    at com.vaadin.pro.licensechecker.MachineId.get(MachineId.java:19)
    at com.vaadin.pro.licensechecker.LicenseChecker.checkLicense(LicenseChecker.java:226)
    at com.vaadin.pro.licensechecker.LicenseChecker.checkLicense(LicenseChecker.java:129)
    at com.vaadin.pro.licensechecker.LicenseChecker.checkLicense(LicenseChecker.java:104)
    at com.vaadin.pro.licensechecker.LicenseChecker.checkLicenseFromStaticBlock(LicenseChecker.java:80)
    at com.vaadin.testbench.TestBench.<clinit>(TestBench.java:35)
    at com.vaadin.testbench.TestBenchTestCase.<clinit>(TestBenchTestCase.java:41)
    ... 68 more
    Suppressed: java.lang.NoSuchMethodError: com/sun/jna/Memory.close()V (loaded from file:/Users/pczuczor/.m2/repository/net/java/dev/jna/jna/5.8.0/jna-5.8.0.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@a506693f) called from class oshi.util.platform.mac.SysctlUtil (loaded from file:/Users/pczuczor/.m2/repository/com/github/oshi/oshi-core/6.4.1/oshi-core-6.4.1.jar by jdk.internal.loader.ClassLoaders$AppClassLoader@a506693f).
        at oshi.util.platform.mac.SysctlUtil.sysctl(SysctlUtil.java:53)
        ... 83 more

It is not happening on Windows, but on Mac, because it has different code execution chain and eventually this will fail:

...
    at oshi.util.Util.freeMemory(Util.java:83)
    at oshi.jna.ByRef$CloseableSizeTByReference.close(ByRef.java:110)
    at oshi.util.platform.mac.SysctlUtil.sysctl(SysctlUtil.java:61)
...

Potential root case is the transitive maven dependency handling (5.8.0 is used rather than 5.13.0)

[INFO] com.vaadin:vaadin-quarkus-development-tests:jar:1.1-SNAPSHOT
[INFO] \- com.vaadin:vaadin-dev-server:jar:23.3-SNAPSHOT:compile
[INFO]    \- com.vaadin:license-checker:jar:1.12.3:compile
[INFO]       \- com.github.oshi:oshi-core:jar:6.4.1:compile
[INFO]          +- net.java.dev.jna:jna:jar:5.8.0:compile (version managed from 5.13.0)
[INFO]          \- net.java.dev.jna:jna-platform:jar:5.13.0:compile
[INFO]             \- (net.java.dev.jna:jna:jar:5.8.0:compile - version managed from 5.13.0; omitted for duplicate)
czp13 commented 1 year ago

Workaround for executing integration tests is to add at least 5.12.0 (first version where the Memory.close() method is added) version to the tag, like this:

    <dependencyManagement>
...
            <dependency>
                <groupId>net.java.dev.jna</groupId>
                <artifactId>jna</artifactId>
                <version>5.12.0</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
mcollovati commented 1 year ago

We need to discover who is bringing in the 5.8.0 version of jna

ErrorProne commented 1 year ago

@mcollovati Oh I had the same problem, based on the gradle dependency output I would say this is based on the quarkus bom

net.java.dev.jna:jna:5.8.0 -> 5.13.0
\--- io.quarkus.platform:quarkus-bom:3.0.3.Final
     \--- project :core
          \--- project :core (*)

https://repo1.maven.org/maven2/io/quarkus/quarkus-bom/3.0.3.Final/quarkus-bom-3.0.3.Final.pom

czp13 commented 1 year ago

Good catch @ErrorProne, thanks!

Maybe:

ErrorProne commented 11 months ago

Note for gradle users, this should fix it:


configurations.all {
    resolutionStrategy {
        // Required (at least on mac) to force the JNA version so license checking works
        force("net.java.dev.jna:jna:5.13.0")
    }
}
mcollovati commented 11 months ago

In a maven project, moving the vaadin bom declaration before the quarkus bom, should fix the issue