-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
How should I handle classes that shouldn't be loaded in native #40713
Comments
/cc @zakkak (native-image) |
Hi @flynndi, if I get this right you have already gone through https://quarkus.io/guides/native-reference#i-get-a-analysiserrorparsingerror-when-building-a-native-executable-due-to-an-unresolvedelementexception-what-can-i-do and decided to proceed with substitutions. I am a bit confused with the obfuscated ( IIRC what's happening here is that GraalVM tries to load the original code in order to substitute it which results in the observed error. So you would need to entirely avoid using Can you provide a reproducer? |
reproducer: https://github.com/flynndi/quarkus-jimmer-extension This is an extension I am developing. When I use this extension for integration testing in native mode, I need to include the PostgreSQL dependency even if I am not using PostgreSQL. I tried using The relevant code is at: Thank you for your help. |
Hi @zakkak, Is modifying the bytecode a feasible solution? I tried modifying the bytecode but received the same error. |
Hello @flynndi, I had a look at the reproducer and it looks like the class is being loaded because Quarkus registers the type Hierarchy of https://github.com/flynndi/quarkus-jimmer-extension-example/blob/main/src/main/kotlin/io/quarkiverse/jimmer/it/entity/UserRole.kt for reflection.
How? I would expect if you modify the bytecode in the jar before passing it to native-image to work. But that's probably not the best approach as it seems too fragile. |
Hello @zakkak , Is there any way to solve this problem? Using the @substitute annotation to replace methods |
The most trivial way is to include the dependency. It will result in more code being packed in the native executable and might prevent some dead code elimination, but should work other than that.
As you already found out unfortunately that won't work as the class is being loaded without the substitutions applied. I wonder if this is something that could be resolved on the GraalVM side though, needs more thought and investigation...
I don't see how that could help here. What did you do in that implementation?
It's still not clear to me how and at what stage you did the bytecode replacement. If you do it before the GraalVM loads the class it should work (but you need to find all the paths that might be reaching the class). |
Regarding Bytecode replacement, This is just a simple experiment, just to see if it works, here is my code: So for now, it can only include dependencies. |
Description
I'm developing a Quarkus extension for an ORM framework. However, I'm encountering some issues when testing with native mode.
The error message I'm receiving is:
This seems to be related to the parsing process during the GraalVM build, particularly with the usage of PGobject in my codebase. However, I'm not sure how to resolve this issue.
Here's a brief overview of my setup:
I'm using Quarkus framework for my application. I have a class PostgresDialect which includes a method unknownReader that uses PGobject. I've tried various approaches such as replacing lambda expressions with anonymous classes and registering substitutions with GraalVM's Feature interface, but the issue persists.
Could anyone provide insights into why GraalVM is encountering this "Unresolved Type" issue and how to resolve it? Any help or suggestions would be greatly appreciated.
The following is the orm framework code
Here's what I did with the quarkus extension
Even when my dialect is not Postgres, I still need to include the Postgres dependency.
Although I can include the Postgres dependency when not using Postgres to ensure the native package builds successfully, this doesn't seem like the correct approach
So, I referred to Quarkus's code, but it didn't work.
It seems that no matter how I replace the unknownReader method, GraalVM still tries to find PGobject.
Thank you in advance!
Repository name
quarkus-jimmer-extension
Short description
jimmer-extension
Repository Homepage URL
https://github.com/flynndi/quarkus-jimmer-extension
Repository Topics
...
Team Members
Additional context
No response
The text was updated successfully, but these errors were encountered: