Automatic Modules Require All Other Modules
You'll learn why automatic modules can access any module without explicit requires declarations.
The Implicit Dependency Rule
When a non-modular JAR becomes an automatic module (by being placed on the module path), it gains a powerful capability: it implicitly requires all other observable modules. This includes:
- All named modules on the module path
- All platform modules (JDK modules)
- The unnamed module (the classpath)
You don't write any requires directives in an automatic module because it doesn't have a module-info.java file. Instead, the Java module system automatically grants it read access to everything.
Why This Behavior Exists
This design solves a critical migration problem. Non-modular code was written without module boundaries—it could depend on anything visible on the classpath. If automatic modules couldn't access everything, existing JARs would break immediately when moved to the module path.
Think of it like giving someone a universal key card when moving into a new building. They can access any room because the system doesn't yet know which specific rooms they actually need.
The Trade-Off
While this makes migration smoother, it also means automatic modules have no encapsulation benefits on the dependency side. They bypass the readability graph's restrictions. However, other explicit modules still cannot read an automatic module's packages unless they explicitly require it.
This asymmetry is intentional: automatic modules get maximum compatibility, while explicit modules maintain strong boundaries.
Practical Implication
When you place an older library JAR on the module path without converting it to a full module, it becomes an automatic module that can "see" your entire application—every module and every classpath class—without any configuration.
Key Takeaway: Automatic modules implicitly require all observable modules (including the unnamed module), ensuring legacy code remains functional during migration without explicit dependency declarations.