Giter VIP home page Giter VIP logo

Comments (4)

fernando-valdez avatar fernando-valdez commented on July 22, 2024

Thanks for reporting this issue. We will take care of it.

from graal.

Karm avatar Karm commented on July 22, 2024

@zakkak I am having trouble to reproduce it running latest native-image with my code snippet.

Directory:

.
./Main.java
./myfile-1.txt
./myfile-2.txt

Files just contain "Hello from file 1" etc.

Code:

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

public class Main {
    public static void main(String[] args) throws IOException {
        for (String s : new String[] { "myfile-1.txt", "myfile-2.txt", "myfile-3.txt" }) {
            try (final InputStream is = Objects.requireNonNull(Main.class.getResourceAsStream("/" + s),
                    "File " + s + " not found.")) {
                System.out.print(new String(is.readAllBytes(), StandardCharsets.US_ASCII));
            } catch (NullPointerException e) {
                System.out.println(e.getMessage());
            }
        }
    }
}

🔴 FAIL GraalVM CE 21.0.2+13.1 (build 21.0.2+13-jvmci-23.1-b30)

$ javac Main.java

$ java -agentlib:native-image-agent=config-output-dir=agent-stuff Main
Hello from file 1
Hello from file 2
File myfile-3.txt not found.

$ cat agent-stuff/resource-config.json 
{
  "resources":{
  "includes":[{
    "pattern":"\\Qmyfile-1.txt\\E"
  }, {
    "pattern":"\\Qmyfile-2.txt\\E"
  }, {
    "pattern":"\\Qmyfile-3.txt\\E"
  }]},
  "bundles":[]
}


$ native-image -H:+UnlockExperimentalVMOptions -H:ThrowMissingRegistrationErrors= -H:ConfigurationFileDirectories=agent-stuff Main main

$ ./main 
Hello from file 1
Hello from file 2
Exception in thread "main" com.oracle.svm.core.jdk.resources.MissingResourceRegistrationError: The program tried to access the resource at path myfile-3.txt without it being registered as reachable. Add it to the resource metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#resources-and-resource-bundles for help
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.resources.MissingResourceRegistrationUtils.missingResource(MissingResourceRegistrationUtils.java:41)
        at org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk.Resources.createInputStream(Resources.java:418)
        at [email protected]/java.lang.Class.getResourceAsStream(DynamicHub.java:821)
        at Main.main(Main.java:9)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

🟢 PASS GraalVM CE 22.0.1+8.1 (build 22.0.1+8-jvmci-b01)

$ rm -rf agent-stuff

$ java -agentlib:native-image-agent=config-output-dir=agent-stuff Main
Hello from file 1
Hello from file 2
File myfile-3.txt not found.

$ cat agent-stuff/resource-config.json 
{
  "resources":{
  "includes":[{
    "pattern":"\\Qmyfile-1.txt\\E"
  }, {
    "pattern":"\\Qmyfile-2.txt\\E"
  }, {
    "pattern":"\\Qmyfile-3.txt\\E"
  }]},
  "bundles":[]
}

$ native-image -H:+UnlockExperimentalVMOptions -H:ThrowMissingRegistrationErrors= -H:ConfigurationFileDirectories=agent-stuff Main main

$ ./main 
Hello from file 1
Hello from file 2
File myfile-3.txt not found.

🟢 PASS (Latest) Mandrel-24.2.0-dev6eefc9c7aae9 (build 24-beta+3-ea)

$ rm -rf agent-stuff

$ java -agentlib:native-image-agent=config-output-dir=agent-stuff Main

$ cat agent-stuff/reachability-metadata.json 
{
  "reflection":[
  ],
  "resources":[{
    "glob":"myfile-1.txt"
  },{
    "glob":"myfile-2.txt"
  },{
    "glob":"myfile-3.txt"
  }],
  "bundles":[],
  "serialization":[
  ],
  "jni":[
    {
      "type":"sun.launcher.LauncherHelper",
      "fields":[{"name":"isStaticMain"},{"name":"noArgMain"}]
    }
  ]
}

$ native-image -H:+UnlockExperimentalVMOptions -H:ThrowMissingRegistrationErrors= -H:ConfigurationFileDirectories=agent-stuff Main main

$ ./main
Hello from file 1
Hello from file 2
File myfile-3.txt not found.

from graal.

zakkak avatar zakkak commented on July 22, 2024

You are right, I probably mixed up the versions when reporting this. Updating the description accordingly. Thanks!

Update: On the other hand the logs clearly show 22.0.1, perhaps I built an older graal version using JDK 22...

from graal.

zakkak avatar zakkak commented on July 22, 2024

The issue is fixed by backporting 2368a2f (part of #7827 which seems to include a number of other fixes probably worth backporting)

from graal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.