Skip to content

8365467: Fix multiple issues in ExplodedImage #26757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

david-beaumont
Copy link
Contributor

@david-beaumont david-beaumont commented Aug 13, 2025

This PR addresses several issues found while adding unit tests for ExplodedImage.
I have added review comments for changes (some of which are a little preferential, but bring the code into line with things like ImageReader in terms of the name choices for variables).
Later it is likely that this code will be adapted for the up-coming preview mode support in Valhalla, so having it unit-testable is important.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8365467: Fix multiple issues in ExplodedImage (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/26757/head:pull/26757
$ git checkout pull/26757

Update a local copy of the PR:
$ git checkout pull/26757
$ git pull https://git.openjdk.org/jdk.git pull/26757/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 26757

View PR using the GUI difftool:
$ git pr show -t 26757

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/26757.diff

Using Webrev

Link to Webrev Comment

* tweaking tests for readability
* Address issues and add unit tests
@bridgekeeper
Copy link

bridgekeeper bot commented Aug 13, 2025

👋 Welcome back david-beaumont! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Aug 13, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk
Copy link

openjdk bot commented Aug 13, 2025

@david-beaumont The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added core-libs [email protected] rfr Pull request is ready for review labels Aug 13, 2025
@mlbridge
Copy link

mlbridge bot commented Aug 13, 2025

Webrevs

Copy link
Contributor Author

@david-beaumont david-beaumont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding explanatory notes for the non-test changes/fixes.


private final FileSystem defaultFS;
private final Path modulesDir;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to make this class actually testable and avoid just using the static field from SystemImage.

private final BasicFileAttributes modulesDirAttrs;

ExplodedImage(Path modulesDir) throws IOException {
defaultFS = FileSystems.getDefault();
String str = defaultFS.getSeparator();
this.modulesDir = modulesDir;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unnecessary assumptions about file systems.

@@ -94,6 +92,11 @@ private final class PathNode extends Node {
this.children = children;
}

@Override
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovered this method was missing during testing. I think this logic is what's needed here, but I would like someone to just double check.

@@ -126,7 +129,7 @@ public Stream<String> getChildNames() {
List<Node> list = new ArrayList<>();
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
for (Path p : stream) {
p = explodedModulesDir.relativize(p);
p = modulesDir.relativize(p);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using static field.

@@ -152,7 +155,7 @@ public long size() {
}

@Override
public void close() throws IOException {
public synchronized void close() throws IOException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nodes map is always accessed synchronised except here, so by synchronizing this we can stop using ConcurrentHashMap.

@@ -275,8 +273,8 @@ private void initNodes() throws IOException {
}
// create "/modules" directory
// "nodes" map contains only /modules/<foo> nodes only so far and so add all as children of /modules
PathNode modulesDir = new PathNode("/modules", new ArrayList<>(nodes.values()));
nodes.put(modulesDir.getName(), modulesDir);
PathNode modulesRootNode = new PathNode("/modules", new ArrayList<>(nodes.values()));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed because there's already "modulesDir" elsewhere.

@@ -78,13 +78,13 @@ void close() throws IOException {
return new ExplodedImage(explodedModulesDir);
}

static final String RUNTIME_HOME;
private static final String RUNTIME_HOME;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiding these prevents unwanted use by other classes (which would make them effectively untestable).

* @modules java.base/jdk.internal.jrtfs java.base/jdk.internal.jimage
* @run junit/othervm java.base/jdk.internal.jrtfs.ExplodedImageTest
*/
public class ExplodedImageTestDriver {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure if a class declaration is needed here. It seems to work fine, but I've seen a case where there wasn't one (but that felt odd). Happy to remove if not wanted.

@@ -0,0 +1,4 @@
modules = \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cargo-culted without a true understand of what's going on. This seems to be what's needed for module access.

* path does not reference a file.
*/
Path underlyingModulesPath(String name) {
if (name.startsWith(MODULES) && name.length() > MODULES.length()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra length test avoids issues when "/modules/" is given, since that should be invalid but otherwise gets turned into a path to the parent dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs [email protected] rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

1 participant