Skip to content
Preptima
hardConceptScenarioMidSeniorStaffLead

You move a service from Java 11 to Java 21 and it fails at startup with InaccessibleObjectException. What changed, and what do you do about it?

5 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Strong encapsulation of JDK internals became the default in JDK 16 and JDK 17 removed the option to relax it wholesale, so deep reflection into a package nobody opened now throws instead of warning.

Was this answer helpful?

Likely follow-ups

  • Which of --add-opens and --add-exports would a serialisation library need to reflect over a JDK type, and why?
  • How do you make these flags apply to your test runner and your production launcher without maintaining the list twice?
  • What replaced sun.misc.Unsafe for the operations libraries were using it for?
  • What else about default platform behaviour changed between JDK 11 and JDK 21 that could alter output with no error at all?

Related questions

Further reading