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

Invalid resource content when using new URL(URL context, String spec) #1349

Closed
voyachek opened this issue Jun 3, 2019 · 6 comments
Closed
Assignees

Comments

@voyachek
Copy link

voyachek commented Jun 3, 2019

I've used new URL(URL context, String spec) in the flowing scenario (native image):

URL url1 = ClassLoader.getSystemResource("r1.txt");
URL url2 = new URL(url1, "r2.txt");
System.out.println(new Scanner(url2.openStream(), "UTF-8").useDelimiter("\\A").next());

line 3 prints content of the resource pointed by url1, but must print the content of the resource pointed by url2 .

@olpaw
Copy link
Member

olpaw commented Jun 4, 2019

@voyachek thanks for your bug report. I can confirm that this is not working as expected.

  • Using -agentlib:native-image-agent=config-output-dir=./META-INF/native-image does not detect the resource usage of "r2.txt" (resource-config.json only contains {"resources":[{"pattern":"r1.txt"}]}
  • A native-image built out of that code prints the contents of "r1.txt" instead of "r2.txt" (on JVM you get the contents from "r2.txt" as expected).

@olpaw
Copy link
Member

olpaw commented Dec 19, 2019

@voyachek can you still reproduce the issue with the latest release?

@peter-hofer
Copy link
Member

peter-hofer commented May 26, 2020

I don't see how we can pragmatically deal with this in the agent: getResource and getSystemResource return only a URL which does not carry the information that it refers to a classpath resource, and even if we knew, we would need to observe any transformation of such URLs and determine whether it still refers to a valid class path resource.

@peter-hofer
Copy link
Member

peter-hofer commented May 26, 2020

Actually, the original issue (sans the agent part) seems like it could still be valid, reopening.

@peter-hofer peter-hofer reopened this May 26, 2020
@jovanstevanovic
Copy link
Member

Should be fixed with PR #3315.

@olpaw
Copy link
Member

olpaw commented Oct 3, 2022

Note that this issue is not about the agent but if native image is able to compose resource URLs at image runtime.
It is fixed by PR #3315 and tested via CI. The test is in com.oracle.svm.test.NativeImageResourceTest#githubIssues:

@olpaw olpaw closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants