Skip to content

Commit 369291b

Browse files
committed
8282444: Module finder incorrectly assumes default file system path-separator character
Reviewed-by: alanb
1 parent d4d12ad commit 369291b

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

src/java.base/share/classes/jdk/internal/module/ModulePath.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -662,11 +662,12 @@ private ModuleReference readJar(Path file) throws IOException {
662662
// -- exploded directories --
663663

664664
private Set<String> explodedPackages(Path dir) {
665+
String separator = dir.getFileSystem().getSeparator();
665666
try {
666667
return Files.find(dir, Integer.MAX_VALUE,
667668
((path, attrs) -> attrs.isRegularFile() && !isHidden(path)))
668669
.map(path -> dir.relativize(path))
669-
.map(this::toPackageName)
670+
.map(path -> toPackageName(path, separator))
670671
.flatMap(Optional::stream)
671672
.collect(Collectors.toSet());
672673
} catch (IOException x) {
@@ -737,7 +738,7 @@ private Optional<String> toPackageName(String name) {
737738
* @throws InvalidModuleDescriptorException if the name is a class file in
738739
* the top-level directory (and it's not module-info.class)
739740
*/
740-
private Optional<String> toPackageName(Path file) {
741+
private Optional<String> toPackageName(Path file, String separator) {
741742
assert file.getRoot() == null;
742743

743744
Path parent = file.getParent();
@@ -751,7 +752,7 @@ private Optional<String> toPackageName(Path file) {
751752
return Optional.empty();
752753
}
753754

754-
String pn = parent.toString().replace(File.separatorChar, '.');
755+
String pn = parent.toString().replace(separator, ".");
755756
if (Checks.isPackageName(pn)) {
756757
return Optional.of(pn);
757758
} else {

test/jdk/java/lang/module/customfs/ModulesInCustomFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
2323

2424
/**
2525
* @test
26+
* @bug 8178380 8282444
2627
* @modules jdk.zipfs
2728
* @library /test/lib
2829
* @build ModulesInCustomFileSystem m1/* m2/*

test/jdk/java/lang/module/customfs/m1/p/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525

2626
public class Main {
2727
public static void main(String[] args) {
28-
q.Hello.hello();
28+
q.r.Hello.hello();
2929
}
3030
}

test/jdk/java/lang/module/customfs/m2/module-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
*/
2323

2424
module m2 {
25-
exports q;
25+
exports q.r;
2626
}

test/jdk/java/lang/module/customfs/m2/q/Hello.java renamed to test/jdk/java/lang/module/customfs/m2/q/r/Hello.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* questions.
2222
*/
2323

24-
package q;
24+
package q.r;
2525

2626
public class Hello {
2727
public static void hello() {

0 commit comments

Comments
 (0)