Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 73014a2

Browse files
committed
8282444: Module finder incorrectly assumes default file system path-separator character
Backport-of: 369291b265e13d625c5f465da9b1854c0d70c435
1 parent 7bdf94b commit 73014a2

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, 2020, 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
@@ -663,11 +663,12 @@ private ModuleReference readJar(Path file) throws IOException {
663663
// -- exploded directories --
664664

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

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

755-
String pn = parent.toString().replace(File.separatorChar, '.');
756+
String pn = parent.toString().replace(separator, ".");
756757
if (Checks.isPackageName(pn)) {
757758
return Optional.of(pn);
758759
} 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)