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

FileSystemNotFoundException when init Graal in Springboot #1348

Closed
JoshuaChen opened this issue Jun 3, 2019 · 16 comments
Closed

FileSystemNotFoundException when init Graal in Springboot #1348

JoshuaChen opened this issue Jun 3, 2019 · 16 comments
Assignees

Comments

@JoshuaChen
Copy link

JoshuaChen commented Jun 3, 2019

I add graal libs in my project to execute JavaScript in Java. My project worked on spingboot framework.
Java Jdk: 9.0.4
spingboot: 2.1.5.RELEASE
graalvm.version : 19.0.0

    <dependency>
       <groupId>org.graalvm.js</groupId>
       <artifactId>js-scriptengine</artifactId>
       <version>${graalvm.version}</version>
   </dependency>
   <dependency>
       <groupId>org.graalvm.js</groupId>
       <artifactId>js</artifactId>
       <version>${graalvm.version}</version>
   </dependency>
   <dependency>
       <groupId>org.graalvm.sdk</groupId>
       <artifactId>graal-sdk</artifactId>
       <version>${graalvm.version}</version>
   </dependency>
   <dependency>
       <groupId>org.graalvm.tools</groupId>
       <artifactId>chromeinspector</artifactId>
       <version>${graalvm.version}</version>
       <scope>runtime</scope>
   </dependency>
   <dependency>
       <groupId>org.graalvm.tools</groupId>
       <artifactId>profiler</artifactId>
       <version>${graalvm.version}</version>
   </dependency>

If I run my project with IDEA directly, graal init success and work fine;
If I buid my project to a fat jar, which contains all libs in it, graal init failed and throw a FileSystemNotFoundException.

at jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(Unknown Source) ~[jdk.zipfs:?]
at jdk.nio.zipfs.ZipFileSystemProvider.getPath(Unknown Source) ~[jdk.zipfs:?]
at java.nio.file.Paths.get(Unknown Source) ~[?:?]
at com.oracle.truffle.polyglot.LanguageCache.collectLanguages(LanguageCache.java:328) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.LanguageCache.createLanguages(LanguageCache.java:246) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.LanguageCache.languages(LanguageCache.java:236) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.PolyglotEngineImpl.languages(PolyglotEngineImpl.java:548) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.PolyglotEngineImpl.initializeLanguages(PolyglotEngineImpl.java:496) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.PolyglotEngineImpl.(PolyglotEngineImpl.java:190) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.PolyglotEngineImpl.(PolyglotEngineImpl.java:172) ~[truffle-api-19.0.0.jar!/:?]
at com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:214) ~[truffle-api-19.0.0.jar!/:?]
at org.graalvm.polyglot.Engine$Builder.build(Engine.java:505) ~[graal-sdk-19.0.0.jar!/:?]
at org.graalvm.polyglot.Context$Builder.build(Context.java:1304) ~[graal-sdk-19.0.0.jar!/:?]
at org.graalvm.polyglot.Context.create(Context.java:697) ~[graal-sdk-19.0.0.jar!/:?]

@wirthi
Copy link
Member

wirthi commented Jun 4, 2019

Hi @JoshuaChen

thanks for your report. I have not seen that specific failure, we had reports of troubles with fat jars before, e.g. oracle/graaljs#125 or oracle/graaljs#135

Can you please check if this might be similar?

Best,
Christian

@shubhendujain
Copy link

I also have exact similar situation as mentioned by @JoshuaChen , instead of unknown source , i got

java.nio.file.FileSystemNotFoundException: null
at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171)

at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157)
at java.nio.file.Paths.get(Paths.java:143)
at com.oracle.truffle.polyglot.LanguageCache.collectLanguages(LanguageCache.java:328)
at com.oracle.truffle.polyglot.LanguageCache.createLanguages(LanguageCache.java:246)
at com.oracle.truffle.polyglot.LanguageCache.languages(LanguageCache.java:236)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.languages(PolyglotEngineImpl.java:548)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.initializeLanguages(PolyglotEngineImpl.java:496)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.(PolyglotEngineImpl.java:190)
at com.oracle.truffle.polyglot.PolyglotEngineImpl.(PolyglotEngineImpl.java:172)
at com.oracle.truffle.polyglot.PolyglotImpl.buildEngine(PolyglotImpl.java:214)
at org.graalvm.polyglot.Engine$Builder.build(Engine.java:505)
at com.oracle.truffle.js.scriptengine.GraalJSEngineFactory.(GraalJSEngineFactory.java:95)

@JoshuaChen
Copy link
Author

@wirthi
Thanks, "using the classpath" can work, but that's not a good solution. I don't want to use it.

@shubhendujain
Copy link

I have further debugged issue of Jar and found issue with following jar
dummy-9.0.0-SNAPSHOT.jar!/BOOT-INF/lib/js-19.0.0.jar

@pszalanski
Copy link

Yes, the issue is probably that the path to the js-19.0.0.jar lies inside the fat jar. This causes an error when trying to retrieve the filesystem path.

We have the exact same issue with a Spring Boot application.

@chineduekwunife
Copy link

@wirthi

I'm facing a similar issue. Spring Boot Application works ok when started from IDE, but once I package application and run inside docker (openjdk:8u111-jdk-alpine) I get FileSystemNotFoundException see error log below.

@chumer based on your comment on oracle/graaljs#125, please when can we expect a fix on this issue?

springBootVersion: 2.1.5.RELEASE

graalVersion: 19.0.0

Dependencies: graal-sdk, truffle-api, js, js-scriptengine

java.nio.file.FileSystemNotFoundException: null
at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171) ~[zipfs.jar:1.8.0_111-internal]
at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157) ~[zipfs.jar:1.8.0_111-internal]
at java.nio.file.Paths.get(Paths.java:143) ~[na:1.8.0_111-internal]
at com.oracle.truffle.polyglot.LanguageCache.collectLanguages(LanguageCache.java:328) ~[truffle-api-19.0.0.jar!/:na]
at com.oracle.truffle.polyglot.LanguageCache.createLanguages(LanguageCache.java:246) ~[truffle-api-19.0.0.jar!/:na]

@dapp1990
Copy link

Hi all,

@pszalanski @chineduekwunife I'm facing the same problem on Springboot, in my case, using JS-19.1.1.

@JoshuaChen I actually tried the "classpath" approach and unfortunately it did not work. I got this error java.lang.NoClassDefFoundError: com/ibm/icu/text/DateFormat, even when I run it using my IDE, I need to investigate further.

I also tried the approach mentioned here but I didn't success. It runs in my IDE but as soon as I generate the jar, run it and the application hits the GraalJS code, the java.nio.file.FileSystemNotFoundException: null is thrown.

In case it is relevant, I created a tiny poc using springboot and GraalJS libraries here, I'm using OpenSDK11.

@xarfai
Copy link

xarfai commented Sep 24, 2019

I had the same problem with a spring boot application.

This is my solution:

try {
   URL res = com.oracle.js.parser.ScriptEnvironment.class.getClassLoader().getResource("/META-INF/truffle/language");
   // initialize the file system for the language file
   FileSystems.newFileSystem(res.toURI(), new HashMap<>());
} catch (Throwable ignored) {
   // in case of starting without fat jar
}
GraalJSScriptEngine engine = GraalJSScriptEngine.create();

That works for me with OpenJDK8 and 11 with the spring-boot-maven-plugin

The POM i used for testing:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>graal-js-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <graalvm.version>19.1.1</graalvm.version>
    </properties>

    <dependencies>

        <!--
        graalvm
        -->
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js</artifactId>
            <version>${graalvm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.graalvm.js</groupId>
            <artifactId>js-scriptengine</artifactId>
            <version>${graalvm.version}</version>
        </dependency>
    </dependencies>

    <build>

        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <!-- 1.8 works as well -->
                    <source>11</source>
                    <target>11</target>                    
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <folders>
                        <folder>
                            graalvm
                        </folder>
                    </folders>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>spring-boot</classifier>
                            <mainClass>
                                test.graaltest.MainApp
                            </mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

@dapp1990
Copy link

Thanks @xarfai I tried on my POC and it worked

@tzezula tzezula self-assigned this Nov 1, 2019
@tzezula
Copy link
Member

tzezula commented Nov 1, 2019

The System property for language home is unset, the code determining the language home using jar location should be more robust.
It seems that the jar is packed in ear (war) and the JarURLConnection.getJarFileURL is pointing into archive file.

@tychedelia
Copy link

Also experiencing this java.nio.file.FileSystemNotFoundException: null on 19.2.0 in a fat jar spring boot app.

@xarfai 's workaround also worked for me as well.

@tzezula
Copy link
Member

tzezula commented Nov 7, 2019

Fixed by: 42180c5.
Targeted into GraalVM 20.0.
Regarding the workaround it's better to use the System.setProperty("js.home",<some_path>) as
the ScriptEnvironment.class.getClassLoader().getResource("/META-INF/truffle/language") will not work in GraalVM 19.3 which uses ServiceLoader based language registration.

@tzezula tzezula closed this as completed Nov 7, 2019
@jonathanrfisher1
Copy link

@tzezula does that also mean your suggested new workaround would not work until using 19.3?

@kvnxiao
Copy link

kvnxiao commented Dec 24, 2019

@tzezula What is the current workaround code in order to get this running with 19.3.0? Where is js.home coming from and being read?

@adveres
Copy link

adveres commented Feb 3, 2020

@xarfai workaround helped me find the solution (thank you!). Debugged and found out in 19.3.1 that the path is different to get the JS jar.

/BOOT-INF/lib/js-19.3.1.jar!/com/oracle/truffle/js/lang/JavaScriptLanguage

Just provide the string /com/oracle/truffle/js/lang/JavaScriptLanguage.class instead of /META-INF/truffle/language.

        try {
            URL res = com.oracle.js.parser.ScriptEnvironment.class.getClassLoader().getResource("/com/oracle/truffle/js/lang/JavaScriptLanguage.class");
            // initialize the file system for the language file
            FileSystems.newFileSystem(res.toURI(), new HashMap<>());
        } catch (Throwable ignored) {
            // in case of starting without fat jar
        }

Otherwise I was in the same boat and had to downgrade my graalvm dependencies to 19.2.1. Hope this helps.

@cdennison
Copy link

This didn't work for me

I verified my class is here JavaScriptLanguage.class
~/.gradle/caches/modules-2/files-2.1/org.graalvm.js/js/22.3.0/42a5d241e5b92589dbf1cbb5dd3eae0360707c8f/js-22.3.0.jar!/com/oracle/truffle/js/lang/JavaScriptLanguage.class

Added the above code and still get

org.graalvm.polyglot.PolyglotException: java.lang.NoClassDefFoundError: com/ibm/icu/text/DateFormat at com.oracle.truffle.js.runtime.JSContextOptions.<clinit>(JSContextOptions.java:457) at com.oracle.truffle.js.lang.JavaScriptLanguage.<clinit>(JavaScriptLanguage.java:182) at com.oracle.truffle.js.lang.JavaScriptLanguageProvider.create(JavaScriptLanguageProvider.java:51) at com.oracle.truffle.polyglot.LanguageCache.loadLanguage(LanguageCache.java:548) at com.oracle.truffle.polyglot.PolyglotLanguageInstance.<init>(PolyglotLanguageInstance.java:100) at com.oracle.truffle.polyglot.PolyglotLanguage.getInitLanguage(PolyglotLanguage.java:152) at com.oracle.truffle.polyglot.PolyglotLanguage.ensureInitialized(PolyglotLanguage.java:142) at com.oracle.truffle.polyglot.PolyglotLanguage.getOptionsInternal(PolyglotLanguage.java:134) at com.oracle.truffle.polyglot.PolyglotLanguage.getOptionValues(PolyglotLanguage.java:202) at com.oracle.truffle.polyglot.PolyglotContextConfig.getLanguageOptionValues(PolyglotContextConfig.java:366) at com.oracle.truffle.polyglot.PolyglotSharingLayer.collectLanguageOptions(PolyglotSharingLayer.java:577) at com.oracle.truffle.polyglot.PolyglotSharingLayer.claimLayerForContext(PolyglotSharingLayer.java:166) at com.oracle.truffle.polyglot.PolyglotEngineImpl.claimSharingLayer(PolyglotEngineImpl.java:359) at com.oracle.truffle.polyglot.PolyglotContextImpl.claimSharingLayer(PolyglotContextImpl.java:551) at com.oracle.truffle.polyglot.PolyglotLanguageContext.ensureCreated(PolyglotLanguageContext.java:551) at com.oracle.truffle.polyglot.PolyglotLanguageContext.ensureInitialized(PolyglotLanguageContext.java:666) at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1324) at com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:63) at org.graalvm.polyglot.Context.eval(Context.java:399) at org.graalvm.polyglot.Context.eval(Context.java:425) at org.acme.graaljs.GraalJavaScriptSimpleFunction.hello(GraalJavaScriptSimpleFunction.java:45) at org.acme.graaljs.GraalJavaScriptSimpleFunction$quarkusrestinvoker$hello_7fddd1e3e354fab6ecbc0092a4fab5e3dd526845.invoke(Unknown Source) at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29) at io.quarkus.resteasy.reactive.server.runtime.QuarkusResteasyReactiveRequestContext.invokeHandler(QuarkusResteasyReactiveRequestContext.java:108) at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:140) at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:555) at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478) at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29) at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:829)

@xarfai workaround helped me find the solution (thank you!). Debugged and found out in 19.3.1 that the path is different to get the JS jar.

/BOOT-INF/lib/js-19.3.1.jar!/com/oracle/truffle/js/lang/JavaScriptLanguage

Just provide the string /com/oracle/truffle/js/lang/JavaScriptLanguage.class instead of /META-INF/truffle/language.

        try {
            URL res = com.oracle.js.parser.ScriptEnvironment.class.getClassLoader().getResource("/com/oracle/truffle/js/lang/JavaScriptLanguage.class");
            // initialize the file system for the language file
            FileSystems.newFileSystem(res.toURI(), new HashMap<>());
        } catch (Throwable ignored) {
            // in case of starting without fat jar
        }

Otherwise I was in the same boat and had to downgrade my graalvm dependencies to 19.2.1. Hope this helps.

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

No branches or pull requests