Identifying Internal API Dependencies
What you'll learn: You'll learn how to detect when your code relies on JDK internal classes or third-party internals that JPMS will block, so you can address these issues before migration.
The Problem: Hidden Dependencies on Internals
Before JPMS, Java developers could access any class in the JDK or third-party libraries—even internal classes like sun.misc.Unsafe or com.sun.net.httpserver.HttpServerImpl. These were never meant to be public APIs, but nothing stopped you from using them.
With strong encapsulation in JPMS, these internal classes become inaccessible unless explicitly opened or exported. If your code (or your dependencies) relies on them, your application will fail with IllegalAccessError at runtime or compilation errors when migrating to modules.
Think of it like this: You've been sneaking into a building's maintenance corridors to take shortcuts. JPMS locks those doors. You need to find all your "backdoor routes" before the locks engage.
How to Identify Internal API Usage
jdeps is your primary tool for detecting internal dependencies:
jdeps --jdk-internals myapp.jar
This scans your JAR and reports:
- Which JDK internal APIs you're using
- Suggested replacements (if available)
- Which classes are calling these internals
For third-party library internals, use:
jdeps -verbose:class myapp.jar
Look for dependencies on packages clearly marked as internal (containing internal, impl, or private in their names).
Acting on the Results
Once identified, you have options:
- Replace internal API calls with standard alternatives
- Use
--add-opensor--add-exportsas temporary workarounds - Update dependencies to versions that no longer use internals
- Contact library maintainers if they depend on internals
Key Takeaway: Use jdeps --jdk-internals to scan your application for dangerous dependencies on internal APIs before migrating to JPMS—catching these early prevents runtime failures and smooths your modularization journey.