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

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 this issue May 15, 2023 · 6 comments

Comments

@czp13
Copy link
Contributor

czp13 commented May 15, 2023

Executing tests with:

  • mvn clean install (independent of adding the Vaadin version like: -Dvaadin.flow.version=23.3-SNAPSHOT)

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
Copy link
Contributor Author

czp13 commented May 15, 2023

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>

@czp13 czp13 changed the title Executing tests (with maven clean install) on MacOs will generate Exception Executing tests (with maven clean install) on MacOs will generate JNA related Exception May 15, 2023
@czp13 czp13 changed the title Executing tests (with maven clean install) on MacOs will generate JNA related Exception Executing tests (with maven clean install) on MacOs will generate JNA related Exception (java.lang.NoSuchMethodError: com/sun/jna/Memory.close()) May 15, 2023
@mcollovati
Copy link
Contributor

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

@ErrorProne
Copy link

ErrorProne commented May 17, 2023

@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
Copy link
Contributor Author

czp13 commented May 17, 2023

Good catch @ErrorProne, thanks!

Maybe:

  • we could just exclude this dependency from the quarkus platform as this is in license-checker as a transitive dependency.
  • Or add the DependencyManagement tag/snippet above to the pom.xml.

@ErrorProne
Copy link

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
Copy link
Contributor

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

ErrorProne added a commit to AliceAndTheBuilders/pro-starter-flow-quarkus that referenced this issue Jul 28, 2023
For mac it is important to set the correct JNA version. In maven this can be done be using a specific order for the bom imports

vaadin/quarkus#124
@mshabarov mshabarov moved this to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenance (Vaadin 10+) Sep 27, 2023
@mshabarov mshabarov moved this from 🔖 Normal Priority (P2) to Internal Backlog / Technical Debt in Vaadin Flow bugs & maintenance (Vaadin 10+) Sep 28, 2023
@mshabarov mshabarov moved this from Internal Backlog / Technical Debt to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenance (Vaadin 10+) Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

3 participants