Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Bytecode manipulation libraries such as ASM, CGLIB and ByteBuddy underpin frameworks, mocking and agents. With the JDK shipping its own Class-File API, how should a large organisation think about its dependence on bytecode generation over the next decade?

Bytecode libraries that lag new class file versions are one of the most common reasons a JDK upgrade gets blocked, and a large organisation depends on them through frameworks, mocking, agents and its own code. Over the next decade I would treat that dependence as a managed risk: prefer frameworks that move generation to build time, which also suits AOT and native images, favour tools that adopt the JDK's Class-File API, limit in-house bytecode generation to a few well-owned libraries, and track every dependency's readiness as a standard part of JDK upgrade planning.

Background to this question

Few engineers write bytecode, yet nearly every Java service runs some generated at startup or during tests: Spring's CGLIB proxies, Hibernate's lazy-loading proxies, Mockito's mocks, APM and coverage agents. When a new JDK arrives, these are often the libraries that fail first. A senior leader is expected to see that pattern across hundreds of services and set a direction that reduces the risk without banning useful tools. In this answer, we will look at where bytecode generation hides in a typical estate, why it blocks upgrades, how the JDK's Class-File API changes the picture, and then the rules I would set: build-time generation, a small set of owned libraries, and upgrade readiness tracking.

1Where Bytecode Generation Hides

Bytecode generation means creating or changing class files while the program runs or builds, instead of writing Java source. In a typical Spring service it happens in several places at once. Spring creates CGLIB subclasses of @Configuration classes and of beans that need proxies for @Transactional or @Async. Hibernate uses ByteBuddy for lazy proxies and optional bytecode enhancement. Mockito's default inline mock maker uses ByteBuddy and an agent to change classes during tests. Observability agents rewrite classes as they load, and coverage tools such as JaCoCo do the same in CI.

Most teams do not choose these libraries directly. They arrive through frameworks, which is why an organisation usually has far more bytecode dependence than anyone has written down.

Step throughBytecode generation in a typical service
  1. Our codesometimes a home-grown proxy or ASM utility
  2. FrameworksSpring CGLIB proxies, Hibernate ByteBuddy proxies
  3. Test toolsMockito inline mocks, JaCoCo instrumentation
  4. AgentsAPM and security agents rewriting classes at load
  5. Bytecode librariesASM, ByteBuddy, Javassist, CGLIB
  6. JDKclass file version changes every six months

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

A change at the bottom has to travel up through every layer before an upgrade can ship.

2Why These Libraries Block Upgrades

Each JDK release may change the class file version and add new features. A bytecode library that has not been updated refuses classes with an unknown version, or fails on a new construct, with errors such as Unsupported class file major version 69 or a message from ByteBuddy that the Java version is not supported yet. The library then needs a release, the framework that bundles it needs a release, and our services need to upgrade the framework.

In a large estate, one lagging agent or an old Mockito pinned by a shared test module can hold back dozens of services. Teams then work around it with flags, such as ByteBuddy's experimental mode, or delay the upgrade, and the delay compounds: the further behind a service is, the more versions it must jump later. I have seen upgrade programmes where most of the effort went into chasing these dependencies rather than into changes to our own code.

3What the JDK's Class-File API Changes

Since Java 24, the JDK ships java.lang.classfile, a standard API for reading, writing and transforming class files that is updated together with each release. A tool built on it can handle the new class file format on the day the JDK is released, because the support comes with the JDK. The JDK has already moved its own internal code off ASM onto it.

This reduces the lag only for tools that adopt it, and adoption will be gradual. The API exists only on JDK 24 and later, so libraries that support Java 17 or 21 will keep ASM or ByteBuddy for years, perhaps using the JDK API when they detect a new enough JDK. So the realistic plan for the decade is not that the problem disappears, but that it shrinks for the tools that move, and that we can choose tools partly by whether they do.

4Prefer Build-Time Generation

The strongest lever is to move generation from run time to build time. Annotation processors such as MapStruct generate ordinary source code that javac compiles, so there is no bytecode library at run time and nothing to break on a new class file version. Spring's AOT engine generates bean registration code and proxy classes during the build. Frameworks designed for build-time work, such as Micronaut or Quarkus, take the same approach.

Build-time generation pays off three ways at once: fewer upgrade blockers, faster startup, and compatibility with native images and AOT caches, which cannot generate classes at run time. When two libraries do the same job, I would prefer the one that generates at build time, and I would ask teams to justify new run-time bytecode generation in design reviews.

5Keep In-House Bytecode Small and Owned

Home-grown bytecode code is the riskiest kind, because nobody outside the company will fix it. A team writes a clever ASM-based proxy or agent, the author moves on, and three years later it blocks the JDK upgrade with nobody who understands it. My rule would be to allow in-house bytecode generation only in a small number of named libraries, each with an owning team, a test suite that runs on every new JDK early-access build, and a documented reason why a standard tool will not do.

For new in-house tools that need bytecode, I would point teams to the Class-File API if they can require JDK 24 or later, and to ByteBuddy otherwise, rather than raw ASM, because a higher-level tool or a JDK API is easier to keep current.

Step throughReviewing a proposal that needs bytecode generation
  1. Can an annotation processor or framework AOT do it?
    Yesuse build-time generationNocontinue
  2. Does a maintained library already do it?
    Yesuse the libraryNocontinue
  3. Can the tool require JDK 24 or later?
    Yesbuild on java.lang.classfileNouse ByteBuddy, not raw ASM
  4. Assign an owning teamand add early-access JDK tests
  5. Record it in the dependency registerreviewed at every upgrade

5 steps in order. Play them, or step through them one at a time.

Most proposals end at the first or second question.

6Make Upgrade Readiness a Standard Process

Finally, I would make dependency readiness a tracked part of every JDK upgrade rather than a surprise. A platform team keeps a register of bytecode-sensitive dependencies across the estate: Spring, Hibernate, Mockito, ByteBuddy, ASM, agents and in-house libraries, with the minimum version that supports each JDK. When a new JDK early-access build appears, CI runs a representative set of services and the in-house libraries on it, so we learn about failures months before the release, not after it.

With an LTS release every two years and feature releases every six months, I would aim for each service to run on the current LTS within about six months of its release. Readiness tracking is what makes that target realistic, and the register also shows where we should push vendors or replace a dependency. The cost is a few days of platform work per release, which is small compared with a programme stalled by one library.

7Follow-up questions

Should we ban run-time bytecode generation entirely?

No. Spring, Hibernate and Mockito rely on it and give real value, and banning them would cost far more than it saves. The goal is to know where it is, prefer build-time options when choosing new tools, keep in-house generation minimal, and test dependencies early against new JDKs.

How would you handle a vendor agent that lags every release?

First, measure it: put it in the readiness register and record how many weeks after each release it gains support. Then raise it with the vendor using that data, and test their early-access builds. If it keeps blocking upgrades, plan a replacement, for example an OpenTelemetry-based agent with a faster release cycle. A dependency that repeatedly stops the whole estate is a business risk, not just a technical annoyance.

What do you tell teams that want to use Mockito's inline mocks?

That they are fine to use, with two notes. Since JDK 21 the JVM warns when an agent is loaded dynamically, so the build should attach Mockito as a Java agent explicitly, as Mockito's documentation suggests. And test dependencies count in the readiness register too, because an old Mockito can block an upgrade as surely as production code.

8Conclusion

In this answer, we saw that bytecode generation is spread through frameworks, test tools, agents and sometimes our own code, and that libraries lagging new class file versions repeatedly block JDK upgrades. The JDK's Class-File API reduces that lag for tools that adopt it, but adoption will be gradual. So the long-term direction is to prefer build-time generation, which also suits AOT and native images, to keep in-house bytecode work in a few owned and tested libraries, and to track each dependency's readiness as a standard step of every JDK upgrade.

What to say in the interviewAbout 80 seconds aloud

Open with

I see bytecode generation as a hidden dependency that most of our services have through Spring proxies, Hibernate, Mockito and agents, and the recurring cost is that these libraries must be updated for every new class file version before we can upgrade the JDK.

Then, if they want more

One lagging agent or old Mockito can hold back dozens of services. The JDK's own Class-File API, final in Java 24, helps because it is updated with the JDK, so tools built on it support a new release on day one, but it only exists from 24 onward, so adoption by libraries will take years.

My direction would have four parts. First, prefer tools that generate code at build time, such as annotation processors and Spring AOT, because that removes run-time bytecode libraries and also suits native images and AOT caches.

Second, limit in-house bytecode generation to a few named libraries with owners and tests against early-access JDK builds, using the Class-File API or ByteBuddy rather than raw ASM. Third, keep a register of bytecode-sensitive dependencies with the version that supports each JDK. Fourth, run representative services on early-access builds so we know about blockers months before a release. That turns upgrade surprises into planned work.

About this answer

Last updated
12 November 2026
Versions it names
Java 24, Java 17, Java 21
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 "Bytecode manipulation libraries such as ASM, CGLIB and ByteBuddy underpin frameworks...": https://scrivio-interview-library.netlify.app/java/reflection-and-method-handles/53d6eaec4e/