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

JNA is not optional when testing on windows #11360

Closed
jaymode opened this issue May 26, 2015 · 0 comments · Fixed by #11378
Closed

JNA is not optional when testing on windows #11360

jaymode opened this issue May 26, 2015 · 0 comments · Fixed by #11378
Assignees

Comments

@jaymode
Copy link
Member

jaymode commented May 26, 2015

The JNA library is listed as optional in the pom file but when running tests in another project without the library, we still try to load it and loading fails with a ClassNotFoundException:

   > Throwable #1: java.lang.NoClassDefFoundError: com/sun/jna/win32/StdCallLibrary$StdCallCallback
   >    at org.elasticsearch.common.jna.Natives.tryVirtualLock(Natives.java:83)
   >    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
   >    at org.elasticsearch.bootstrap.BootstrapForTesting.<clinit>(BootstrapForTesting.java:52)
   >    at org.elasticsearch.test.ElasticsearchTestCase.<clinit>(ElasticsearchTestCase.java:97)
   >    at java.lang.Class.forName0(Native Method)
   >    at java.lang.Class.forName(Class.java:274)
   > Caused by: java.lang.ClassNotFoundException: com.sun.jna.win32.StdCallLibrary$StdCallCallback
   >    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
   >    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   >    at java.security.AccessController.doPrivileged(Native Method)
   >    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   >    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
   >    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
   >    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
   >    ... 7 more

which then cascades into:

   > Throwable #1: java.lang.NoClassDefFoundError: org.elasticsearch.test.ElasticsearchTestCase
   >    at java.lang.Class.getDeclaredMethods0(Native Method)
   >    at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
   >    at java.lang.Class.getDeclaredMethods(Class.java:1860)
   >    at com.carrotsearch.randomizedtesting.ClassModel$3.members(ClassModel.java:215)
   >    at com.carrotsearch.randomizedtesting.ClassModel$3.members(ClassModel.java:212)
   >    at com.carrotsearch.randomizedtesting.ClassModel$ModelBuilder.build(ClassModel.java:85)
   >    at com.carrotsearch.randomizedtesting.ClassModel.methodsModel(ClassModel.java:224)
   >    at com.carrotsearch.randomizedtesting.ClassModel.<init>(ClassModel.java:207)
   >    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

This seems to be provoked only on Windows by the Natives#tryVirtualLock method currently.

@jaymode jaymode self-assigned this May 26, 2015
jaymode added a commit to jaymode/elasticsearch that referenced this issue May 27, 2015
Today, JNA is a optional dependency in the build but when running tests or running
with mlockall set to true, JNA must be on the classpath for Windows systems since
we always try to load JNA classes when using mlockall.

The old Natives class was renamed to JNANatives, and a new Natives class is
introduced without any direct imports on JNA classes. The Natives class checks to
see if JNA classes are available at startup. If the classes are available the Natives
class will delegate to the JNANatives class. If the classes are not available the
Natives class will not use the JNANatives class, which results in no additional attempts
to load JNA classes.

Additionally, all of the JNA classes were moved to the bootstrap package and made
package private as this is the only place they should be called from.

Closes elastic#11360
jaymode added a commit to jaymode/elasticsearch that referenced this issue May 27, 2015
Today, JNA is a optional dependency in the build but when running tests or running
with mlockall set to true, JNA must be on the classpath for Windows systems since
we always try to load JNA classes when using mlockall.

The old Natives class was renamed to JNANatives, and a new Natives class is
introduced without any direct imports on JNA classes. The Natives class checks to
see if JNA classes are available at startup. If the classes are available the Natives
class will delegate to the JNANatives class. If the classes are not available the
Natives class will not use the JNANatives class, which results in no additional attempts
to load JNA classes.

Additionally, all of the JNA classes were moved to the bootstrap package and made
package private as this is the only place they should be called from.

Closes elastic#11360
jaymode added a commit that referenced this issue May 27, 2015
Today, JNA is a optional dependency in the build but when running tests or running
with mlockall set to true, JNA must be on the classpath for Windows systems since
we always try to load JNA classes when using mlockall.

The old Natives class was renamed to JNANatives, and a new Natives class is
introduced without any direct imports on JNA classes. The Natives class checks to
see if JNA classes are available at startup. If the classes are available the Natives
class will delegate to the JNANatives class. If the classes are not available the
Natives class will not use the JNANatives class, which results in no additional attempts
to load JNA classes.

Additionally, all of the JNA classes were moved to the bootstrap package and made
package private as this is the only place they should be called from.

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

Successfully merging a pull request may close this issue.

1 participant