RFR: 8335989: Implement Module Import Declarations (Second Preview) [v4]

Alan Bateman alanb at openjdk.org
Tue Oct 29 17:28:11 UTC 2024


On Thu, 24 Oct 2024 06:40:42 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> This is a current patch for module imports declarations, second preview. At least the JEP number and preview revision will need to be updated in `jdk.internal.javac.PreviewFeature.Feature`, but otherwise I believe this is ready to receive feedback.
>> 
>> The main changes are:
>> - `requires transitive java.base;` is permitted, under the preview flag. Both javac and the runtime module system are updated to accept this directive when preview is enabled.
>> - the `java.se` module is using `requires transitive java.base;`, and is deemed to be participating in preview, so its classfile version is not tainted. Runtime is updated to access `requires transitive java.base;` in any `java.*`, considering all of them to be participating in preview. Can be tighten up to only `java.se` is desired.
>> - the types imported through module imports can be shadowed using on-demand imports. So, for example, having:
>> 
>> import module java.base;
>> import module java.desktop;
>> ...
>> List l;//ambigous
>> 
>> but:
>> 
>> import module java.base;
>> import module java.desktop;
>> import java.util.*;
>> ...
>> List l;//not ambigous, reference to java.util.List
>
> Jan Lahoda has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 18 commits:
> 
>  - Updating PreviewFeature metadata
>  - Cleanup.
>  - Merge branch 'master' into JDK-8335989
>  - Merge branch 'master' into JDK-8335989
>  - Reflecting review feedback.
>  - Cleanup.
>  - Cleanup.
>  - Fixing tests
>  - Adding a separate scope for module imports.
>  - Cleanup.
>  - ... and 8 more: https://git.openjdk.org/jdk/compare/964d8d22...94b8bf6d

src/java.base/share/classes/jdk/internal/module/ModuleInfo.java line 193:

> 191:         int minor_version = in.readUnsignedShort();
> 192:         int major_version = in.readUnsignedShort();
> 193:         boolean isPreview = minor_version == ClassFile.PREVIEW_MINOR_VERSION;

I think this will need to throw invalidModuleDescriptor if isPreview && major version != ClassFile.latestMajorVersion, otherwise the check in readModuleAttribute will be defeated by hand craft class files (the VM doesn't read module-info class files so it won't reject it, and this code is called from exposed APIs such as ModuleDescriptor.read).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/21431#discussion_r1821270533


More information about the compiler-dev mailing list