Summary
Cyclic dependency among modules is properly detected and reported by javac.
Problem
Currently, javac sometimes does not report cyclic dependencies among (source) modules. This example shows the issue:
src/m1/module-info.java:
module m1 {
requires m2;
}
src/m2/module-info.java:
module m2 {
requires m3;
requires m1;
}
src/m3/module-info.java:
module m3 { }
which should be reported a cyclic dependency by the compiler.
Solution
The compiler should detect, and report, any cyclic dependency in the module graph.
Specification
Javac is not in sync with the spec, it contradicts JLS 9, 7.7.1. Dependences, which says "It is a compile-time error if resolution, as described in the java.lang.module package specification, with the current module as the only root module, fails for any of the reasons described in the java.lang.module package specification.", and the javadoc for java.lang.module specifies and error if "The algorithm in this step enumerates the same module name twice. This indicates a cycle in the 'requires' directives, disregarding any 'transitive' modifiers." javac will detect, and report, any cyclic dependence in the module graph.
- csr of
-
JDK-8202832 cycle detection depends on ordering of requires directives
-
- Closed
-