Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8282444: Module finder incorrectly assumes default file system path-s…
…eparator character

Backport-of: 369291b265e13d625c5f465da9b1854c0d70c435
  • Loading branch information
ChrisHegarty committed Mar 24, 2022
1 parent 13140f9 commit 3c123f3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2022, 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 @@ -663,11 +663,12 @@ private ModuleReference readJar(Path file) throws IOException {
// -- exploded directories --

private Set<String> explodedPackages(Path dir) {
String separator = dir.getFileSystem().getSeparator();
try {
return Files.find(dir, Integer.MAX_VALUE,
((path, attrs) -> attrs.isRegularFile() && !isHidden(path)))
.map(path -> dir.relativize(path))
.map(this::toPackageName)
.map(path -> toPackageName(path, separator))
.flatMap(Optional::stream)
.collect(Collectors.toSet());
} catch (IOException x) {
Expand Down Expand Up @@ -738,7 +739,7 @@ private Optional<String> toPackageName(String name) {
* @throws InvalidModuleDescriptorException if the name is a class file in
* the top-level directory (and it's not module-info.class)
*/
private Optional<String> toPackageName(Path file) {
private Optional<String> toPackageName(Path file, String separator) {
assert file.getRoot() == null;

Path parent = file.getParent();
Expand All @@ -752,7 +753,7 @@ private Optional<String> toPackageName(Path file) {
return Optional.empty();
}

String pn = parent.toString().replace(File.separatorChar, '.');
String pn = parent.toString().replace(separator, ".");
if (Checks.isPackageName(pn)) {
return Optional.of(pn);
} else {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, 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 All @@ -23,6 +23,7 @@

/**
* @test
* @bug 8178380 8282444
* @modules jdk.zipfs
* @library /test/lib
* @build ModulesInCustomFileSystem m1/* m2/*
Expand Down
2 changes: 1 addition & 1 deletion test/jdk/java/lang/module/customfs/m1/p/Main.java
Expand Up @@ -25,6 +25,6 @@

public class Main {
public static void main(String[] args) {
q.Hello.hello();
q.r.Hello.hello();
}
}
2 changes: 1 addition & 1 deletion test/jdk/java/lang/module/customfs/m2/module-info.java
Expand Up @@ -22,5 +22,5 @@
*/

module m2 {
exports q;
exports q.r;
}
Expand Up @@ -21,7 +21,7 @@
* questions.
*/

package q;
package q.r;

public class Hello {
public static void hello() {
Expand Down

1 comment on commit 3c123f3

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.