feat(java): Add ForyFeature for GraalVM Native Image
Why?
Reflective access to private constructors in the GraalVM Native Image environment is limited. ObjectCreator failures return the wrong type, causing a ClassCastException. Lack of friendly GraalVM error messages.
What does this PR do?
Added GraalVM environment detection and special processing, optimized ObjectCreator implementation, and added unit tests
Related issues
Close #2697
Does this PR introduce any user-facing change?
- [x] Does this PR introduce any public API change?
- [x] Does this PR introduce any binary protocol compatibility change?
Benchmark
ParentNoArgCtrObjectCreator should be able to generate a constructor of parent class to create instance of subclass using jdk.internal.reflect.ReflectionFactory. It's strange why it can't work
I was wrong. I should not use unsafe to escape this problem. I should use GraalVM's reachability metadata to solve the problem of ReflectionFactory.
What should I do? I always encounter a configuration problem. When running in the graalvm environment, there is always a problem of native-image command parsing error. What should I do? I have tried many methods (crying)
@chaokunyang I'm very sorry. My current coding skills aren't enough to completely fix this bug, and I haven't passed the CI test. Could you please make some changes on my branch to fix this bug? I've tried many methods, but the files are messed up. I'm sorry that after nearly two weeks, I still haven't solved this bug. I'm very sorry. Could you please refactor and upgrade my messy code?
Hi @mengnankkkk, thanks for your hard work and for letting me know the situation. I understand that you’ve spent quite a bit of time on this bug, and I appreciate the effort you’ve put in.
I’ll take a look at your branch, refactor the code, and work on fixing the bug so we can get the CI tests to pass. Don’t worry about the current state — debugging can be tricky, and each attempt helps us better understand the problem.
Thanks again for your contributions! I’ll update the PR once I’ve made the necessary changes.
Hi @mengnankkkk, thanks for your hard work and for letting me know the situation. I understand that you’ve spent quite a bit of time on this bug, and I appreciate the effort you’ve put in.
I’ll take a look at your branch, refactor the code, and work on fixing the bug so we can get the CI tests to pass. Don’t worry about the current state — debugging can be tricky, and each attempt helps us better understand the problem.
Thanks again for your contributions! I’ll update the PR once I’ve made the necessary changes.
I'm very sorry. I pushed AI to find a solution to the problem, but it didn't seem to solve it and made the code look even more shitty. I'm very sorry./(ㄒoㄒ)/~~