Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ public static int getPreviewFlags(String name, Predicate<String> hasEntry) {
*
* <p>Based on the module links, the flags are:
* <ul>
* <li>{@code FLAGS_HAS_PREVIEW_VERSION} if <em>any</em> referenced
* <li>{@code FLAGS_HAS_PREVIEW_VERSION} if <em>any</em> linked
* package has a preview version.
* <li>{@code FLAGS_IS_PREVIEW_ONLY} if <em>all</em> referenced packages
* <li>{@code FLAGS_IS_PREVIEW_ONLY} if <em>all</em> linked packages
* are preview only.
* </ul>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private ArrayList<Node> processPackagesDirectory(boolean previewMode) {
ImageLocation pkgDir = getLocation(offsets.get(i));
int flags = pkgDir.getFlags();
// A package subdirectory is "preview only" if all the modules
// it references have that package marked as preview only.
// it links have that package marked as preview only.
// Skipping these entries avoids empty package subdirectories.
if (previewMode || !ImageLocation.isPreviewOnly(flags)) {
pkgDirs.add(ensureCached(newDirectory(pkgDir.getFullName())));
Expand Down
10 changes: 6 additions & 4 deletions src/java.base/share/classes/jdk/internal/jimage/ModuleLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public static ModuleLink forEmptyPackage(String moduleName, boolean isPreview) {
/**
* Returns the appropriate FLAGS_PKG_HAS_XXX_VERSION constant according to
* whether the associated package is defined for preview mode.
*
* @param isPreview whether the associated package is defined for preview mode.
*/
private static int previewFlag(boolean isPreview) {
return isPreview ? FLAGS_PKG_HAS_PREVIEW_VERSION : FLAGS_PKG_HAS_NORMAL_VERSION;
Expand Down Expand Up @@ -261,7 +263,7 @@ public Integer next() {
public static void write(
List<ModuleLink> links, IntBuffer buffer, Function<String, Integer> nameEncoder) {
if (links.isEmpty()) {
throw new IllegalArgumentException("References list must be non-empty");
throw new IllegalArgumentException("Links list must be non-empty");
}
int expectedCapacity = 2 * links.size();
if (buffer.capacity() != expectedCapacity) {
Expand All @@ -271,13 +273,13 @@ public static void write(
// This catches exact duplicates in the list.
links.stream().reduce((lhs, rhs) -> {
if (lhs.compareTo(rhs) >= 0) {
throw new IllegalArgumentException("References must be strictly ordered: " + links);
throw new IllegalArgumentException("Links must be strictly ordered: " + links);
}
return rhs;
});
// Distinct references can have the same name (but we don't allow this).
// Distinct links can have the same name (but we don't allow this).
if (links.stream().map(ModuleLink::name).distinct().count() != links.size()) {
throw new IllegalArgumentException("Module links names must be unique: " + links);
throw new IllegalArgumentException("Module link names must be unique: " + links);
}
if (links.stream().filter(ModuleLink::hasResources).count() > 1) {
throw new IllegalArgumentException("At most one module link can have resources: " + links);
Expand Down
8 changes: 4 additions & 4 deletions test/jdk/jdk/internal/jimage/ImageLocationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class ImageLocationTest {
@ValueSource(strings = {
"/modules/modfoo/com",
"/modules/modfoo/com/foo/Foo.class"})
public void getFlags_resourceNames(String name) {
public void getPreviewFlags_resourceNames(String name) {
String previewName = previewName(name);

int noPreviewFlags =
Expand All @@ -74,12 +74,12 @@ public void getFlags_resourceNames(String name) {
"/modules/modfoo",
"/modules/modfoo/META-INF",
"/modules/modfoo/META-INF/module-info.class"})
public void getFlags_zero(String name) {
public void getPreviewFlags_zero(String name) {
assertEquals(0, ImageLocation.getPreviewFlags(name, Set.of(name)::contains));
}

@Test
public void getFlags_packageFlags() {
public void getPreviewFlags_packageFlags() {
assertThrows(
IllegalArgumentException.class,
() -> ImageLocation.getPreviewFlags("/packages/pkgname", p -> true));
Expand Down Expand Up @@ -115,7 +115,7 @@ public void getPackageFlags_previewOnly() {
ModuleLink.forEmptyPackage("modbar", true),
ModuleLink.forEmptyPackage("modbaz", true));
int previewOnlyFlags = ImageLocation.getPackageFlags(links);
// Note the asymmetry between this and the getFlags() case. Unlike
// Note the asymmetry between this and the getPreviewFlags() case. Unlike
// module resources, there is no concept of a separate package directory
// existing in the preview namespace, so a single entry serves both
// purposes, and hasPreviewVersion() and isPreviewOnly() can both be set.
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/jdk/internal/jimage/ModuleLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void writeBuffer_multiplePackagesWithResources() {

@Test
public void writeBuffer_badOrdering() {
// Badly ordered because preview references should come first.
// Badly ordered because preview links should come first.
List<ModuleLink> links = Arrays.asList(
forEmptyPackage("alpha", false),
forEmptyPackage("beta", true));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -241,25 +241,25 @@ static void assertContainsResources(Node dirNode, String... resourceNames) {

static void assertNonEmptyLink(ModuleLink link, String modName) {
assertEquals(modName, link.name(), "Unexpected module name: " + link);
assertTrue(link.hasResources(), "Expected non-empty linkerence: " + link);
assertTrue(link.hasResources(), "Expected non-empty link: " + link);
assertFalse(link.isPreviewOnly(), "Expected not preview-only: " + link);
}

static void assertEmptyLink(ModuleLink link, String modName) {
assertEquals(modName, link.name(), "Unexpected module name: " + link);
assertFalse(link.hasResources(), "Expected empty linkerence: " + link);
assertFalse(link.hasResources(), "Expected empty link: " + link);
assertFalse(link.isPreviewOnly(), "Expected not preview-only: " + link);
}

static void assertNonEmptyPreviewOnlyLink(ModuleLink link, String modName) {
assertEquals(modName, link.name(), "Unexpected module name: " + link);
assertTrue(link.hasResources(), "Expected empty linkerence: " + link);
assertTrue(link.hasResources(), "Expected non-empty link: " + link);
assertTrue(link.isPreviewOnly(), "Expected preview-only: " + link);
}

static void assertEmptyPreviewOnlyLink(ModuleLink link, String modName) {
assertEquals(modName, link.name(), "Unexpected module name: " + link);
assertFalse(link.hasResources(), "Expected empty linkerence: " + link);
assertFalse(link.hasResources(), "Expected empty link: " + link);
assertTrue(link.isPreviewOnly(), "Expected preview-only: " + link);
}
}