Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8203342

cycle detection depends on ordering of requires directives

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P2 P2
    • 11
    • tools
    • None
    • behavioral
    • low
    • Some source code containing module cycles may already exist, javac will produce compile-time errors for these. Such modules didn't work at runtime, so such cases should be fairly rare.
    • Language construct

      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.

            jlahoda Jan Lahoda
            alanb Alan Bateman
            Vicente Arturo Romero Zaldivar
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: