-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
base: master
Are you sure you want to change the base?
Conversation
* tweaking tests for readability * Address issues and add unit tests
👋 Welcome back david-beaumont! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@david-beaumont The following label will be automatically applied to this pull request:
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. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 {} |
There was a problem hiding this comment.
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 = \ |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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.
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
Issue
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