JDK-8350781 : Compiler Implementation of Module Import Declarations
  • Type: CSR
  • Component: tools
  • Sub-Component: javac
  • Priority: P4
  • Status: Finalized
  • Resolution: Unresolved
  • Fix Versions: 25
  • Submitted: 2025-02-26
  • Updated: 2025-04-24
Related Reports
CSR :  
Relates :  
Relates :  
Description
Summary
-------

We propose to finalize the module import declarations feature. There are no non-editorial change to the specifications.

Problem
-------

The module import declarations feature have been through two rounds of preview. The experience suggests we can make the feature final and permanent.

Solution
--------

The following will happen for finalization of this feature:

- the preview addendums for the JLS and JVMS will be folded into the corresponding main, non-preview specifications, mostly as is. Specifications will undergo editorial changes.
- javac will no longer require `--enable-preview` command line option for the use of `import module <module-name>;` and `requires transitive java.base;`.
- both javac and the JDK runtime will accept `module-info` classfiles with `requires transitive java.base;`.
- relevant API methods currently marked with `@PreviewFeature` will be made final and permanent by removing this annotation
- the default startup script for JShell will be adjusted based on the current JShell's behavior when `--enable-preview` is specified

Specification
-------------

The use of `import module ...` and `requires transitive java.base;` in source code will no longer require `--enable-preview` from Java compilers.
The use of the `requires transitive java.base;` directive in `module-info.class` will no longer require `--enable-preview`, at compile time and at runtime.

The current copies of the JLS and JVMS drafts are attached.

A specdiff showing the API changes is attached and also available for convenience here:
https://cr.openjdk.org/~jlahoda/JDK-8344708/specdiff.00/overview-summary.html

<h3> JShell </h3>

The default startup script for JShell currently differs depending on whether the `--enable-preview` command line option is used.

If the `--enable-preview` command line option is not used, the default script lists a hard-coded list of packages. If the `--enable-preview` command line option is used, the JShell's default startup script is:

    import module java.base;
    import static java.io.IO.*;

This will be changed as follows:

<strong>When there's no `--enable-preview` command line option and source level is greater of equal to 25:</strong>

The default startup script will be:

    import module java.base;

<strong>When there's the `--enable-preview` command line option:</strong>

Until https://openjdk.org/jeps/8344699 is integrated, the default startup script will be:

    import module java.base;
    import static java.io.IO.*;

When https://openjdk.org/jeps/8344699 is integrated, the default startup script will be:

    import module java.base;

<strong>When source level is lower than 25:</strong>

The default startup script will be:

    import java.io.*;
    import java.math.*;
    import java.net.*;
    import java.nio.file.*;
    import java.util.*;
    import java.util.concurrent.*;
    import java.util.function.*;
    import java.util.prefs.*;
    import java.util.regex.*;
    import java.util.stream.*;

Which is the current default without the `--enable-preview` command line option.

Comments
Moving updated request to Provisional.
04-04-2025

I've added more information on JShell and more detailed explanation of what will happen. Please let me know if more is needed. Thanks!
28-03-2025

[~jlahoda] or [~gbierman], the JEP text mentions updates to jshell. Those jshell behavioral changes should be described in this CSR or a separate one. Moving back to Draft.
27-03-2025