Java / GraalVM Interview questions
Why doesn't Native Image support arbitrary bytecode generation at runtime?
Libraries like CGLIB, older versions of certain ORMs, and some AOP frameworks work by generating brand-new class bytecode on the fly at runtime - for example, subclassing an entity to add lazy-loading behavior - and then loading that freshly-minted class into the running JVM.
Native Image's AOT compilation model has already finished compiling and discarding everything not statically reachable by the time the application runs; there's no bytecode-to-machine-code compiler present at runtime anymore to process a newly generated class, and no classloader mechanism built for arbitrary, previously-unseen bytecode.
Frameworks that rely heavily on this pattern (classic dynamic proxying via bytecode generation rather than java.lang.reflect.Proxy) typically need a build-time-friendly alternative - many modern frameworks like Spring and Hibernate have shipped Native Image-compatible modes that move this class generation to build time instead, precisely to work around this limitation.
More Related questions...