Java / GraalVM Interview questions
Describe reflection configuration in native image?
Because Native Image performs a closed-world static analysis at build time, it can only see the classes, methods, and fields that its analysis can prove are reachable from the entry point - reflective calls built from a runtime string (like Class.forName(someVariable)) are invisible to it.
To fix that, you declare the reflectively-used elements in a JSON configuration file, conventionally META-INF/native-image/reflect-config.json:
[ { "name": "com.example.MyPlugin", "allDeclaredConstructors": true, "allPublicMethods": true } ]
This tells the builder to keep that class's constructors and public methods available for reflection in the final binary. Rather than writing these by hand, most teams generate them automatically using the native-image-agent, which records actual reflection, JNI, resource, and proxy usage while running the app normally on a JVM.
More Related questions...