Skip to content

Conversation

@mengnankkkk
Copy link
Contributor

@mengnankkkk mengnankkkk commented Oct 4, 2025

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?

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

@chaokunyang
Copy link
Collaborator

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

@mengnankkkk
Copy link
Contributor Author

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.

@mengnankkkk mengnankkkk reopened this Oct 9, 2025
@mengnankkkk
Copy link
Contributor Author

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
Copy link
Collaborator

chaokunyang commented Oct 24, 2025

image you can make it use Unsafe for object allocation too when running in graalvm

* null, allowing the serializer to use alternative approaches like Unsafe.allocateInstance.
*/
private static ObjectStreamClass safeObjectStreamClassLookup(Class<?> type) {
if (GraalvmSupport.isGraalRuntime()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use GraalvmSupport.IS_GRAALVM_NATIVE_IMAGE

@mengnankkkk
Copy link
Contributor Author

@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?

@chaokunyang
Copy link
Collaborator

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.

@mengnankkkk
Copy link
Contributor Author

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ㄒ)/~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Java][Native Image] ObjectCreator sometimes produces Object under GraalVM 25

2 participants