-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
In native mode a static instance cannot load resources as the resource URL references a jar in the path #27777
Comments
This is actually the expected behavior as all statically reachable code is "frozen" at native image build time. To make your code work, you need to write a GraalVM substitution that resets the fields. |
Hi @geoand, Thanks a mill for your answer. Though I'm surprised this is the expected behaviour. Why is it expected to have a wrong resource URL? |
Yeah, I completely see your point, it's definitely not intuitive behavior - I actually wonder if GraalVM could detect this - @zakkak any idea? |
@geoand this might seem like a noob question but which lib contains the annotations?
Is there a guide how to use them? |
@zakkak can give you all the info about to the latest changes |
This is a caveat of ahead of time compilation. Note that
|
Thanks a million @zakkak |
Describe the bug
When an object is instantiated as static then the object or any objects instantiated by it are not able to load resources.
If I instantiate the object as non static, then when the object tries to load a resource, the resource URL looks like this:
If I instantiate the same object as static, then the resource URL looks like this:
This is the exception I get when I try to open a resource loaded by a static object:
Expected behavior
the resource URL is the same for both scenarios (static and non static resource loader objects)
Actual behavior
when the object which loads the resource is instantiated as static then the resource URL references a non-existent jar file:
How to Reproduce?
Link to a minimal project to reproduce the issue: https://drive.google.com/file/d/1ZeIZypM1rCpA0SVsUW33uwi2hV1GlntF/view?usp=sharing
build it with
sample code:
'''
public class QuarkusBug implements RequestHandler<Map<String, Object>, Map<String, Object>> {
@slf4j
public static class Loader {
private URL resource;
}
// THE FAILING ONE
private static Loader loader = new Loader();
// THE PASSING ONE
// private Loader loader = new Loader();
public QuarkusBug() {
loader.read();
}
@OverRide
public Map<String, Object> handleRequest(Map<String, Object> request, Context context) {
return request;
}
}
'''
Output of
uname -a
orver
Linux 5.15.0-46-generic #49~20.04.1-Ubuntu SMP Thu Aug 4 19:15:44 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Output of
java -version
openjdk version "11.0.16" 2022-07-19
GraalVM version (if different from Java)
GraalVM 22.2.0 Java 11 CE (quay.io/quarkus/ubi-quarkus-native-image:22.2-java11)
Quarkus version or git rev
2.12.0.Final
Build tool (ie. output of
mvnw --version
orgradlew --version
)Apache Maven 3.6.3
Additional information
No response
The text was updated successfully, but these errors were encountered: