Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Spring, Hibernate, Mockito and many internal tools depend on run-time proxies and generated subclasses. As the JDK tightens integrity by default and AOT becomes common, what long-term risks does this dependence carry, and how would you steer your platform?

Run-time proxies and generated subclasses depend on bytecode libraries that must learn every new class file version, on deep reflection and Java agents that the JDK's integrity-by-default work keeps restricting, and on discovering classes at run time, which AOT compilation and native images do not allow. To steer the platform, we prefer frameworks and versions that generate code at build time or provide AOT hints, keep our own proxy-based tools few, owned and tested on each new JDK early, and make every agent and opened package explicit.

Why this question is asked

Spring, Hibernate and Mockito have made run-time code generation invisible: we write an annotation and a proxy appears. Across a large platform that convenience adds up to a deep dependence on a few bytecode libraries and on JVM permissions the JDK team is steadily narrowing. Interviewers ask this at principal level to see whether we can name the specific risks, separate the ones we control from the ones we do not, and turn them into a direction for years rather than a reaction to the next broken upgrade. In this answer, we will recap where proxies come from, go through three sources of risk, and then set out how we would steer.

1A Quick Recap: Where Generated Classes Come From

A run-time proxy is a class that did not exist when we compiled our code. Spring generates CGLIB subclasses for @Transactional, @Async and @Configuration classes, and JDK interface proxies in other cases. Hibernate generates subclasses of our entities, with ByteBuddy, to make lazy loading work. Mockito creates mocks, by default by changing the bytecode of the real class through an instrumentation agent. Each of these writes bytecode while the application runs and defines new classes, often with deep reflection into our private members.

That gives three moving parts we depend on: a bytecode library that understands the current class file format, permission from the JVM to reflect deeply or to instrument classes, and the ability to discover what to generate at run time. Each one is under pressure.

Step throughWhat a proxy-based feature depends on
  1. Our codeannotations such as @Transactional, @Entity, mocks
  2. Frameworkdecides what to generate at run time
  3. Bytecode libraryCGLIB, ByteBuddy, ASM: must read each class file version
  4. JVM permissionsdeep reflection, opened packages, Java agents
  5. Runtime modelJIT on a class path, or AOT and native image

5 layers, from the top down. Step through them one at a time.

A change in any lower layer can break every feature above it.

2Risk 1: Bytecode Libraries Must Track Every Release

Every JDK release since Java 10 increments the class file version, and each release may add new bytecode features. A library that reads class files to generate subclasses refuses, or worse misbehaves, when it meets a version it does not know. That is why a JDK upgrade often fails first in a test: Mockito or Hibernate pulls in a ByteBuddy version that cannot yet handle the new class files, and the fix is a library upgrade that may lag the JDK by weeks.

The JDK is reducing this risk from its side. JDK 24 made the Class-File API final, a standard java.lang.classfile package that always understands the running JDK's format, and libraries may move to it over time. Until they do, every proxy-heavy framework in our stack sits on the critical path of each JDK upgrade.

3Risk 2: Integrity by Default Narrows Deep Reflection and Agents

The JDK's direction, often summarised as integrity by default, is that code should not be able to break the guarantees of other code without the application owner explicitly allowing it. We have already seen the steps: strong encapsulation of JDK internals in JDK 16 and 17, so setAccessible on non-opened packages throws. JDK 21 started warning when an agent is loaded dynamically into a running JVM, which is exactly how Mockito's inline mock maker and some profilers attach by default, with a plan to disallow it by default in a future release. Restrictions on Unsafe's memory access followed, and further work targets deep reflection that changes final fields (check the current JEPs for the exact status).

None of this forbids frameworks. It makes the permissions explicit: an agent must be named with -javaagent on the command line, and a package must be opened with an opens clause or an --add-opens flag. The risk is that our platform relies on these permissions implicitly, in hundreds of launch scripts and test configurations nobody owns, and discovers them only when a release turns a warning into an error.

YAML
# the dynamic attach warning seen in many test runs on JDK 21 and later (wording varies)
WARNING: A Java agent has been loaded dynamically (byte-buddy-agent.jar)
WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning
WARNING: Dynamic loading of agents will be disallowed by default in a future release
# the explicit, future-proof form for test JVMs
-javaagent:${mockitoAgentJar}

4Risk 3: AOT and Native Images Need Everything Known at Build Time

A GraalVM native image compiles the application ahead of time into one executable, assuming a closed world: every class that can ever run must be known at build time. A proxy class invented at run time does not fit that model, and neither does reflection on members the build did not see. Project Leyden, bringing AOT caches to the standard JVM, works in the same direction: work that is predictable can be done before startup.

Frameworks have answered this. Spring's AOT engine generates bean definitions at build time, pre-generates the CGLIB classes, and records hints for the JDK proxies and reflection that remain; Hibernate can enhance entities at build time instead of at run time; Quarkus and Micronaut were built around build-time generation from the start. But an internal library that creates proxies dynamically, or a framework version without AOT support, blocks a service from these options regardless of what the rest of the stack supports.

5How We Would Steer the Platform

The direction follows from the risks. We prefer frameworks, and versions of them, that generate code at build time or provide AOT hints, and we keep the platform's framework versions current, because each upgrade usually brings support for the newest JDK's class files and better AOT coverage. For our own code, we keep proxy-based internal tools few. Each one needs an owner, a reason it cannot be a plain decorator or a build-time processor, and tests that run on JDK early-access builds months before a release, so we learn about breakage before the teams do.

Then we make permissions explicit and central. The platform's base image and test configuration declare the agents and opened packages we accept, each with an owner, and nothing is copied into individual services. Test JVMs load Mockito's agent with -javaagent instead of attaching dynamically. A quarterly report shows each service's agents, opens flags and native image readiness, which turns a vague long-term risk into a short list of named items that shrinks.

We do not try to remove proxies. Spring's transaction proxies are well maintained and AOT-aware, and rewriting them would cost far more than it saves. The goal is to depend on generated classes only through a small number of maintained frameworks, with every permission they need written down.

Risks and what we do about each
RiskEarly signalOur response
New class file versionTests fail on early-access JDKUpgrade framework BOM first; test EA builds
Dynamic agent restrictionsAgent loaded dynamically warningDeclare -javaagent explicitly in test config
Deep reflection limitsInaccessibleObjectExceptionCentral, owned opens list; upgrade libraries
AOT and native imagesMissing hints at native buildPrefer AOT-ready frameworks; few internal proxies

6Follow-up questions

Should we ban run-time proxies in new internal libraries?

Not ban, but require a reason. Most internal uses, such as adding logging or metrics around an interface, can be a plain decorator class or a build-time generated one, which is easier to debug and needs no permissions. When a run-time proxy is truly needed, it should use the JDK's Proxy or a mainstream library, register AOT hints, and have an owner.

What is the concrete risk with Mockito?

Its default inline mock maker attaches an instrumentation agent at run time, which recent JDKs warn about and plan to disallow by default. The fix is cheap: configure the test JVM to load Mockito's agent with -javaagent, which the Mockito documentation describes. The bigger lesson is to make every such permission explicit in shared build configuration.

How do you measure progress on native image readiness?

We pick a small set of representative services and build them as native images in CI, even if we do not deploy them that way. Build failures and missing-hint warnings tell us which frameworks or internal tools still rely on run-time discovery, and the list shrinks as we upgrade or replace them.

7Conclusion

In this answer, we saw that proxies and generated subclasses depend on bytecode libraries that must track each class file version, on deep reflection and Java agents that the JDK's integrity-by-default work keeps restricting, and on run-time discovery that AOT and native images do not allow. We steer by preferring frameworks that generate code at build time or provide AOT hints, keeping internal proxy-based tools few, owned and tested early on new JDKs, and making every agent and opened package explicit and central.

What to say in the interviewAbout 90 seconds aloud

Open with

I see three long-term risks. First, proxies and generated subclasses come from bytecode libraries like ByteBuddy, CGLIB or ASM, and every JDK release bumps the class file version, so those libraries have to catch up before our upgrade can go through; that's usually the first thing to break on a new JDK.

Then, if they want more

The Class-File API in JDK 24 should help over time, but not yet everywhere. Second, integrity by default: deep reflection into JDK internals already fails since 16 and 17, JDK 21 warns when agents are loaded dynamically, which is exactly what Mockito's inline mock maker does by default, and that's planned to be disallowed by default.

So implicit permissions spread across launch scripts become future failures. Third, AOT and native images assume everything is known at build time, so run-time proxies and reflection need build-time generation or hints.

How I'd steer: prefer frameworks and versions that generate code at build time or provide AOT hints, like Spring's AOT engine or build-time entity enhancement, and keep the framework BOM current. Keep internal proxy-based tools few, each with an owner, tested on JDK early-access builds.

And make permissions explicit and central: agents declared with -javaagent, opens flags in one owned list, with a regular report per service. I wouldn't remove proxies, just depend on them through a few maintained frameworks.

About this answer

Last updated
12 November 2026
Versions it names
Java 21, Java 10, Java 16, Java 24
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Spring, Hibernate, Mockito and many internal tools depend on run-time proxies and...": https://scrivio-interview-library.netlify.app/java/reflection-and-method-handles/c977b726f5/