oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.35k stars 1.63k forks source link

java.nio.file.ProviderNotFoundException: Provider "jrt" not found when run groovy code in java #2809

Open wangzhongshan opened 4 years ago

wangzhongshan commented 4 years ago

Describe the issue

java.nio.file.ProviderNotFoundException: Provider "jrt" not found when run groovy code in java

Steps to reproduce the issue Please include both build steps as well as run steps

  1. git clone https://github.com/wangzhongshan/graalvm-groovy-demo.git
  2. mvn clean package
  3. native-image --no-fallback --report-unsupported-elements-at-runtime --allow-incomplete-classpath --verbose -jar ./target/graalvm-groovy-demo-1.0-SNAPSHOT.jar ./target/app
  4. ./target/app

Describe GraalVM and your environment:

More details

    java.nio.file.ProviderNotFoundException: Provider "jrt" not found
        at java.nio.file.FileSystems.newFileSystem(FileSystems.java:357)
        at java.nio.file.FileSystems.newFileSystem(FileSystems.java:286)
        at org.codehaus.groovy.vmplugin.v9.ClassFinder.newFileSystem(ClassFinder.java:158)
        at org.codehaus.groovy.vmplugin.v9.ClassFinder.find(ClassFinder.java:118)
        at org.codehaus.groovy.vmplugin.v9.ClassFinder.find(ClassFinder.java:107)
        at org.codehaus.groovy.vmplugin.v9.Java9.doFindClasses(Java9.java:107)
        at org.codehaus.groovy.vmplugin.v9.Java9.getDefaultImportClasses(Java9.java:85)
        at org.codehaus.groovy.control.ResolveVisitor.<clinit>(ResolveVisitor.java:641)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:499)
        at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:807)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:499)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.println(DefaultGroovyMethods.java:803)
        at com.wzs.GroovyScript.doCall(GroovyScript.groovy:9)
        at com.wzs.App.main(App.java:15)
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: Unsupported method java.lang.ClassLoader.loadClass(String, boolean) is reachable
        at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:86)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:569)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:869)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:979)
        at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:967)
        at org.codehaus.groovy.vmplugin.v9.Java9.getDefaultImportClasses(Java9.java:88)
        at org.codehaus.groovy.control.ResolveVisitor.<clinit>(ResolveVisitor.java:641)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:499)
        at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:807)
        at com.oracle.svm.core.hub.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:350)
        at com.oracle.svm.core.hub.ClassInitializationInfo.initialize(ClassInitializationInfo.java:270)
        at java.lang.Class.ensureInitialized(DynamicHub.java:499)
        at org.codehaus.groovy.runtime.DefaultGroovyMethods.println(DefaultGroovyMethods.java:803)
        at com.wzs.GroovyScript.doCall(GroovyScript.groovy:9)
        at com.wzs.App.main(App.java:15)
jramirez-isc commented 4 years ago

Hi, thanks for reporting this. I'm able to reproduce the issue you reported. I'll investigate more about it and report back.

swiftma commented 4 years ago

any progress on this?I have the same issue.

dmlloyd commented 4 years ago

Does it even make sense to have JRT support in a native image? Why would it have that filesystem at run time?

swiftma commented 4 years ago

the code simply calls a groovy script , which calls println, then triggers the exception stack ....

KengoTODA commented 2 years ago

Does it even make sense to have JRT support in a native image? Why would it have that filesystem at run time?

In my case it is necessary to use BCEL's SyntheticRepository class. This class try to parse CLASSPATH which is created based on java.home property, and throw the exception like below:

Exception in thread "main" java.lang.ExceptionInInitializerError
        at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:315)
        at org.apache.bcel.util.SyntheticRepository.getInstance(SyntheticRepository.java:44)
        at org.apache.bcel.Repository.<clinit>(Repository.java:37)
(omit)
Caused by: java.nio.file.ProviderNotFoundException: Provider "jrt" not found
        at java.nio.file.FileSystems.getFileSystem(FileSystems.java:234)
        at org.apache.bcel.util.ModularRuntimeImage.<init>(ModularRuntimeImage.java:58)
        at org.apache.bcel.util.ClassPath$JrtModules.<init>(ClassPath.java:356)
        at org.apache.bcel.util.ClassPath.<init>(ClassPath.java:569)
        at org.apache.bcel.util.ClassPath.<clinit>(ClassPath.java:443)
        at com.oracle.svm.core.classinitialization.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:375)
        at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:295)
        ... 21 more

My motivation to use BCEL is accelerate static bytecode analysis.

mukel commented 2 years ago

Pass -H:+AllowJRTFileSystem. Note that you won't be able to inspect modules within the native executable, but you can open and inspect other modules e.g. you still need to have the jmods around.

KengoTODA commented 2 years ago

Thanks, I've tried the option, and faced another UnsatisfiedLinkError in the same constructor. java.home is pointing the home of GraalVM v21.1.0 (Java 11). I'll keep investigating on this issue.

Exception in thread "main" java.lang.UnsatisfiedLinkError: jdk.internal.jimage.NativeImageBuffer.getNativeMap(Ljava/lang/String;)Ljava/nio/ByteBuffer; [symbol: Java_jdk_internal_jimage_NativeImageBuffer_getNativeMap or Java_jdk_internal_jimage_NativeImageBuffer_getNativeMap__Ljava_lang_String_2]
        at com.oracle.svm.jni.access.JNINativeLinkage.getOrFindEntryPoint(JNINativeLinkage.java:153)
        at com.oracle.svm.jni.JNIGeneratedMethodSupport.nativeCallAddress(JNIGeneratedMethodSupport.java:57)
        at jdk.internal.jimage.NativeImageBuffer.getNativeMap(NativeImageBuffer.java)
        at jdk.internal.jimage.BasicImageReader.<init>(BasicImageReader.java:95)
        at jdk.internal.jimage.ImageReader$SharedImageReader.<init>(ImageReader.java:224)
        at jdk.internal.jimage.ImageReader$SharedImageReader.open(ImageReader.java:238)
        at jdk.internal.jimage.ImageReader.open(ImageReader.java:67)
        at jdk.internal.jimage.ImageReader.open(ImageReader.java:71)
        at jdk.internal.jrtfs.SystemImage.open(SystemImage.java:59)
        at jdk.internal.jrtfs.JrtFileSystem.<init>(JrtFileSystem.java:90)
        at jdk.internal.jrtfs.JrtFileSystemProvider.getTheFileSystem(JrtFileSystemProvider.java:207)
        at jdk.internal.jrtfs.JrtFileSystemProvider.getFileSystem(JrtFileSystemProvider.java:221)
        at java.nio.file.FileSystems.getFileSystem(FileSystems.java:231)
        at org.apache.bcel.util.ModularRuntimeImage.<init>(ModularRuntimeImage.java:58)
        at org.apache.bcel.util.ClassPath$JrtModules.<init>(ClassPath.java:356)
        at org.apache.bcel.util.ClassPath.<init>(ClassPath.java:569)
roland-burke commented 2 years ago

@KengoTODA Have you found any solution for that UnsatisfiedLinkError? Because i got the same using jboss Path Utils

KengoTODA commented 2 years ago

Yes, it is working with GraalVM 22.0.0.2. My repo is https://github.com/KengoTODA/spotbugs-cli, not sure if it helps you or not tho.

l-mh-95 commented 11 months ago

I have also encountered the same problem. Is there a feasible solution?