DEV Community

Discussion on: Building a 22 Megabytes Microservice with Java, Javalin and GraalVM

Collapse
5422m4n profile image
Sven Assmann

I really dislike that there may always be runtime errors that GraalVM can't predict at compile time (correct me if i'm wrong).

I wonder how it is possible after compilation to encounter runtime errors? As I see it the compiler does the static type checks, so at runtime there shouldn't be any surprises. Do I overlook something?

Collapse
birdayz profile image
Johannes Brüderl Author • Edited on

I quote from GraalVM docs:

SubstrateVM tries to resolve these elements through a static analysis that
detects calls to the reflection API. Where the analysis fails the program
elements reflectively accessed at run time must be specified 
during native image generation in a configuration file [...]

So yeah it's best-effort only, but no guarantee to detect your stuff. Reflection is a hacky side-step to manipulate or create objects etc, so no guarantees. Javac can't give you guarantees about runtime behavior of reflection, so GraalVM can't do it as well.