You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Version: com.github.jnr:jnr-ffi:2.0.7 found on Maven repository
AsmClassLoader throws java.lang.ClassNotFoundException: jnr.ffi.provider.jffi.NativeClosureProxy when it is about to define a class but jnr-ffi classes are not loaded by the ClassLoader.getSystemClassLoader. This is usually triggered by creating closures from jnr-ffi.
One reason for jnr-ffi not being loaded by the system class loader is because it is part of a ScalaTest test case, in which case ScalaTest seems to have its own class loader that loads both jnr-ffi and the class being tested. Because of this, the same application works fine when run stand-alone, but fails when tested by ScalaTest.
The reason, I think, is that AsmClassLoader is created in NativeRuntime, when an AsmClassLoader is created with ClassLoader.getSystemClassLoader() as its parent. The problem here is that NativeRuntime itself may not be loaded by the system class loader.
The following program can reproduce this problem. But if the test body is copied to a stand-alone application, no exceptions will be thrown.
Run starting. Expected test count is: 1
AsmClassLoaderTest:
AsmClassLoader
Caught exception from getClosurePointer: class java.lang.RuntimeException: java.lang.NoClassDefFoundError: jnr/ffi/provider/jffi/NativeClosureProxy
Point1
syscl=sun.misc.Launcher$AppClassLoader@33909752
thisl=java.net.URLClassLoader@33c7353a
rtl=java.net.URLClassLoader@33c7353a
cml=java.net.URLClassLoader@33c7353a
acl=jnr.ffi.provider.jffi.AsmClassLoader@2de8284b
acl.getParent=sun.misc.Launcher$AppClassLoader@33909752
acl2=jnr.ffi.provider.jffi.AsmClassLoader@396e2f39
acl2.getParent=java.net.URLClassLoader@33c7353a
cls1=class jnr.ffi.provider.jffi.NativeClosureProxy
Caught exception from AsmClassLoader: class java.lang.ClassNotFoundException: jnr.ffi.provider.jffi.NativeClosureProxy
cls3=class jnr.ffi.provider.jffi.NativeClosureProxy
Caught exception from system class loader: class java.lang.ClassNotFoundException: jnr.ffi.provider.jffi.NativeClosureProxy
Point2
- should load jnr-ffi-related classes
Run completed in 461 milliseconds.
Total number of tests run: 1
Suites: completed 1, aborted 0
Tests: succeeded 1, failed 0, canceled 0, ignored 0, pending 0
All tests passed.
Stack trace of AsmClassLoader.loadClass:
java.lang.ClassNotFoundException: jnr.ffi.provider.jffi.NativeClosureProxy
at java.lang.ClassLoader.findClass(ClassLoader.java:530)
at jnr.ffi.provider.jffi.AsmClassLoader.findClass(AsmClassLoader.java:51)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at jnr.ffi.provider.jffi.AsmClassLoaderTest$$anonfun$1.apply$mcV$sp(AsmClassLoaderTest.scala:45)
at jnr.ffi.provider.jffi.AsmClassLoaderTest$$anonfun$1.apply(AsmClassLoaderTest.scala:11)
at jnr.ffi.provider.jffi.AsmClassLoaderTest$$anonfun$1.apply(AsmClassLoaderTest.scala:11)
at org.scalatest.Transformer$$anonfun$apply$1.apply$mcV$sp(Transformer.scala:22)
at org.scalatest.OutcomeOf$class.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.FlatSpecLike$$anon$1.apply(FlatSpecLike.scala:1647)
at org.scalatest.Suite$class.withFixture(Suite.scala:1122)
at org.scalatest.FlatSpec.withFixture(FlatSpec.scala:1683)
at org.scalatest.FlatSpecLike$class.invokeWithFixture$1(FlatSpecLike.scala:1644)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1656)
at org.scalatest.FlatSpecLike$$anonfun$runTest$1.apply(FlatSpecLike.scala:1656)
at org.scalatest.SuperEngine.runTestImpl(Engine.scala:306)
at org.scalatest.FlatSpecLike$class.runTest(FlatSpecLike.scala:1656)
at org.scalatest.FlatSpec.runTest(FlatSpec.scala:1683)
at org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1714)
at org.scalatest.FlatSpecLike$$anonfun$runTests$1.apply(FlatSpecLike.scala:1714)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:413)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:401)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:390)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:427)
at org.scalatest.SuperEngine$$anonfun$traverseSubNodes$1$1.apply(Engine.scala:401)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.SuperEngine.traverseSubNodes$1(Engine.scala:401)
at org.scalatest.SuperEngine.org$scalatest$SuperEngine$$runTestsInBranch(Engine.scala:396)
at org.scalatest.SuperEngine.runTestsImpl(Engine.scala:483)
at org.scalatest.FlatSpecLike$class.runTests(FlatSpecLike.scala:1714)
at org.scalatest.FlatSpec.runTests(FlatSpec.scala:1683)
at org.scalatest.Suite$class.run(Suite.scala:1424)
at org.scalatest.FlatSpec.org$scalatest$FlatSpecLike$$super$run(FlatSpec.scala:1683)
at org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1760)
at org.scalatest.FlatSpecLike$$anonfun$run$1.apply(FlatSpecLike.scala:1760)
at org.scalatest.SuperEngine.runImpl(Engine.scala:545)
at org.scalatest.FlatSpecLike$class.run(FlatSpecLike.scala:1760)
at org.scalatest.FlatSpec.run(FlatSpec.scala:1683)
at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:55)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2563)
at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2557)
at scala.collection.immutable.List.foreach(List.scala:381)
at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2557)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1044)
at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1043)
at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2722)
at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
at org.scalatest.tools.Runner$.main(Runner.scala:860)
at org.scalatest.tools.Runner.main(Runner.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher$.main(ScalaTestLauncher.scala:20)
at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher.main(ScalaTestLauncher.scala)
I copied the test body to a standalone Scala App, run it again, and output is:
Version: com.github.jnr:jnr-ffi:2.0.7 found on Maven repository
AsmClassLoader throws
java.lang.ClassNotFoundException: jnr.ffi.provider.jffi.NativeClosureProxy
when it is about to define a class butjnr-ffi
classes are not loaded by theClassLoader.getSystemClassLoader
. This is usually triggered by creating closures fromjnr-ffi
.One reason for
jnr-ffi
not being loaded by the system class loader is because it is part of a ScalaTest test case, in which case ScalaTest seems to have its own class loader that loads bothjnr-ffi
and the class being tested. Because of this, the same application works fine when run stand-alone, but fails when tested by ScalaTest.The reason, I think, is that AsmClassLoader is created in
NativeRuntime
, when anAsmClassLoader
is created withClassLoader.getSystemClassLoader()
as its parent. The problem here is thatNativeRuntime
itself may not be loaded by the system class loader.The following program can reproduce this problem. But if the test body is copied to a stand-alone application, no exceptions will be thrown.
When run with ScalaTest, the output is:
Stack trace of
AsmClassLoader.loadClass
:I copied the test body to a standalone Scala App, run it again, and output is:
The text was updated successfully, but these errors were encountered: