javajava-9java-platform-module-systemaccess-specifier

Difference between Exports, Indirect Exports, Requires and Indirect Requires in Java9?


I was going through the API docs for jdk.accessibility and noticed that it lists all these separately.

  1. The modules with scope requires in one module are all consuming module's Indirect Requires?

  2. The module-info.java for the module is as follows:

    module jdk.accessibility {
        requires transitive java.desktop;
    
        exports com.sun.java.accessibility.util;
    }
    

    and for java.desktop is something like(trying to include varying -

    module java.desktop {
        ...
        requires java.prefs;
        ...
        requires transitive java.xml;
        exports java.applet;
        ...
        exports sun.awt to
            javafx.swing,
            jdk.accessibility,
            oracle.desktop;
        opens javax.swing.plaf.basic to jdk.jconsole;
        ...
        uses javax.sound.sampled.spi.MixerProvider;
        ...
        provides javax.sound.sampled.spi.MixerProvider with
            com.sun.media.sound.DirectAudioDeviceProvider,
            com.sun.media.sound.PortMixerProvider;
    

    But then the doc for jdk.accessibility does not mention sun.awt as either Requires or Indirect Requires or Indirect Exports. What's the reason of inconsistency here?

Looking for examples of the difference between these that can help understand what is happening in (2) and what shall be followed as a practice for us to adapt to module structure using Java9.


Solution

  • Note that in:

    module java.desktop {
        ...
        ...
        exports sun.awt to
            javafx.swing,
            jdk.accessibility,
            oracle.desktop;
    }
    

    that sun.awt is a package, not a module name. (Here is another example.) So it makes sense that sun.awt would not be mentioned in the doc, as java.desktop is already cited.

    Edit: Also, note that for clients of the jdk.accessibility module, the sun.awt package is not accessible. That is, it is exported by java.desktop for use by jdk.accessibility but does not become part of its API. I have confirmed (example here) that this is true even though jdk.accessibility requires java.desktop as transitive.