Quick revision
The short answer
Free access to JDK internals let libraries innovate quickly, but it meant every JDK upgrade could break something in ways nobody could predict. Strong encapsulation and integrity by default let the JDK change its internals and improve performance and security safely, at the cost of a one-time migration for libraries and a few explicit flags. My stance for the organisation is to accept the defaults, keep every exception listed with an owner, and push vendors to supported APIs, because that lowers the cost of staying current for years.
What to remember
In this answer, we followed the JDK from free access to internals, through warnings and enforced encapsulation, to integrity by default for agents, JNI and Unsafe. Free access helped libraries move fast but made upgrades risky and limited what the JDK could guarantee; the new defaults cost a one-time migration and a few explicit flags but make upgrades predictable. For leadership, the framing is cost of ownership with concrete numbers, and the stance is to accept the defaults, list every exception with an owner, push vendors to supported APIs and measure how quickly we adopt each LTS.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Free access to JDK internals let libraries innovate quickly, but it meant every JDK upgrade could break something in ways nobody could predict. Strong encapsulation and integrity by default let the JDK change its internals and improve performance and security safely, at the cost of a one-time migration for libraries and a few explicit flags. My stance for the organisation is to accept the defaults, keep every exception listed with an owner, and push vendors to supported APIs, because that lowers the cost of staying current for years.
Background to this question
Leaders do not need to know what --add-opens does, but they do feel its effects: upgrades that take quarters, security findings that cannot be patched quickly, and teams that are afraid to touch the runtime. A senior engineer is asked this question to show they can translate a long technical evolution into a business trade-off and a clear policy. In this answer, we will recap the journey from free access to integrity by default, explain what each side of the trade-off costs, frame it for leadership with an example, and set out a long-term stance.
1A Quick Recap of the Journey
For about twenty years, anything public in the JDK could be used by anyone, and with reflection even private fields were within reach. Libraries such as serialisers, mocking frameworks and high-performance collections built on these internals because it made them faster or more convenient. Java 9 introduced modules and encapsulation with a permissive default; Java 16 made denial the default; Java 17 removed the global switch.
The same idea is now being applied to the remaining back doors, under the name integrity by default. Loading an agent into a running JVM prints a warning since Java 21, calling native code through JNI prints a warning on recent releases unless it is enabled explicitly, and the memory access methods of sun.misc.Unsafe are deprecated for removal and warn when used. The pattern is always the same: the capability stays available, but the application owner must grant it on the command line. Exact releases and defaults differ, so check your version.
- Java 8 and earlierAny library can use internals and reflection
- Java 9Modules; internals permitted with a warning
- Java 16 and 17Denied by default, then enforced
- Java 21 onwardsWarnings for dynamic agents, JNI, Unsafe memory
- DirectionEach capability needs an explicit grant
5 steps in order. Play them, or step through them one at a time.
2What Free Access Cost Us
Free access was good for innovation, and we should say so. Libraries could ship features years before the JDK offered a supported API. But the bill came at upgrade time. Because any library could depend on any internal detail, the JDK team could not know what a change would break, and neither could we. An upgrade meant testing everything and hoping. In a large organisation, that uncertainty turns into long upgrade cycles, old runtimes with known vulnerabilities, and expensive heroics when a support deadline arrives.
There is also an integrity cost. If any library can rewrite private fields or patch classes at run time, the JDK cannot fully guarantee that a final field is constant or that a security check runs. That limits optimisations such as constant folding and makes security reviews harder, because the guarantees the language promises are not really guaranteed.
3What Integrity by Default Costs, and What It Buys
The cost is real but bounded. Libraries had to move to supported APIs, such as VarHandle, MethodHandles, the Foreign Function and Memory API and the Class-File API, and applications had to upgrade those libraries. Where an old dependency cannot be fixed yet, we add a specific flag such as --add-opens or --enable-native-access, which is a little operational work and needs to be documented.
What we buy is predictability. When applications only use supported APIs, a JDK upgrade becomes routine: a dependency bump, a test run and a rollout. The JDK team can change internals for performance, as compact strings and compact object headers did, without breaking us. And the flags themselves become a map of our risk: every exception tells us exactly which component still depends on something unsupported.
4Framing It for Leadership
With leadership, I would avoid the module vocabulary and talk about cost of ownership. An example helps. Say our last upgrade from 11 to 17 took three quarters for 150 services, and roughly half of that time went into finding and fixing libraries that used JDK internals. Each quarter on an old runtime is a quarter of security patches we apply late or not at all. The new defaults mean that, once our dependencies are clean, the next upgrade should take weeks, not quarters, and the JDK can no longer be broken by a library doing something hidden.
So the message is: we pay a migration cost once, much of it already paid, in exchange for cheaper and safer upgrades every year afterwards. That is a standard investment trade, and leaders are comfortable with it once the numbers are concrete.
5Our Long-Term Stance
The policy I would set has four parts. We accept the JDK's integrity defaults and do not fight them with blanket flags. Every exception, whether an --add-opens, an agent or native access, is listed in one place with the service, the reason, an owner and a review date, so the list can only shrink deliberately. We push vendors and open-source projects to supported APIs, and we choose new dependencies partly on whether they already do. And we measure the result as the time it takes the fleet to adopt a new LTS release, because that is the number leadership cares about.
This stance also means saying no sometimes. A product that only works with broad flags or by attaching agents at run time is a long-term liability, and its cost belongs in the purchasing decision.
6Follow-up questions
What would you do if a critical vendor product needs broad --add-opens flags?
Allow it as a listed exception with an owner, ask the vendor for a date to support the current defaults, and include that commitment in the next contract renewal. If the vendor has no plan, the product becomes a risk item, and we start evaluating alternatives before the next LTS upgrade forces the issue.
Does integrity by default hurt observability tools that use agents?
Not if they are attached the supported way. An agent started with -javaagent on the command line is an explicit grant and does not trigger the dynamic loading warning. The warnings target agents attached to a running JVM without the owner's consent, which is also what attackers would do.
How do you know the policy is working?
Track two numbers: the count of listed exceptions across the fleet, which should fall each quarter, and the time from a new LTS release to most services running on it. If upgrades are getting faster and exceptions are shrinking, the policy works.
7Conclusion
In this answer, we followed the JDK from free access to internals, through warnings and enforced encapsulation, to integrity by default for agents, JNI and Unsafe. Free access helped libraries move fast but made upgrades risky and limited what the JDK could guarantee; the new defaults cost a one-time migration and a few explicit flags but make upgrades predictable. For leadership, the framing is cost of ownership with concrete numbers, and the stance is to accept the defaults, list every exception with an owner, push vendors to supported APIs and measure how quickly we adopt each LTS.
Open with
I would frame it as a trade between short-term convenience and long-term cost of ownership. For twenty years, libraries could reach into JDK internals freely, which let them innovate quickly, but it meant nobody could predict what a JDK upgrade would break.
Then, if they want more
Our upgrades took quarters, and part of the fleet stayed on old runtimes with late security patches. The JDK has moved step by step to strong encapsulation, enforced since Java 17, and now to integrity by default, where dynamic agents, JNI and Unsafe memory access need an explicit grant from the application owner.
That lets the JDK team change internals for performance and security without breaking us. The cost was a one-time migration for libraries and a few flags for exceptions, much of which we have already paid.
For leadership I would use our own numbers, for example how long the last upgrade took and how much of it was internal API problems, and say the next one should take weeks once dependencies are clean.
Our long-term stance would be: accept the defaults, never use blanket flags, keep every exception in a central list with an owner and review date, push vendors to supported APIs and factor it into buying decisions, and measure how fast we adopt each new LTS. That number is the real return on this investment.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 16, Java 17, Java 21, Java 9
- 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.
- Official documentation
- The Java Language Specification, Java SE 21, Java SE 21 API documentation
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 "The JDK spent years moving from free access to internals, through warnings, to enforced...": https://scrivio-interview-library.netlify.app/java/modules/8c1048943f/