RFR: 8231179: Investigate why tools/javac/options/BCPOrSystemNotSpecified.java fails on Window
Jonathan Gibbons
jjg at openjdk.java.net
Thu Jan 14 21:52:05 UTC 2021
On Thu, 14 Jan 2021 21:14:40 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Hi all,
>>
>> The statement `String sourcePath = file.getName();` in method `prepareBCP(Path target)` would use `DirectoryFileObject::getName` which is shown below.
>>
>> @Override @DefinedBy(Api.COMPILER)
>> public String getName() {
>> return relativePath.resolveAgainst(userPackageRootDir).toString(); // <-----------------
>> }
>>
>> And the `DirectoryFileObject::getName` would use `RelativePath::resolveAgainst` which is shown below
>>
>> public Path resolveAgainst(Path directory) throws /*unchecked*/ InvalidPathException {
>> String sep = directory.getFileSystem().getSeparator(); // <---------------------
>> return directory.resolve(path.replace("/", sep));
>> }
>>
>> We can see that `RelativePath::resolveAgainst` use file system separator instead of operating system separator. In method `prepareBCP`, the file system should be JRT file system, but we don't need to know actually which file system to be used. We only need to use the same file system separator so that the test can run as expected.
>>
>> This patch fixes the test by using the file system separator instead of operating system separator.
>>
>> Thank you for taking the time to review.
>>
>> Best Regards.
>
> test/langtools/tools/javac/options/BCPOrSystemNotSpecified.java line 213:
>
>> 211: String sourcePath = file.getName();
>> 212: // Here, we should use file system separator instead of the operating system separator.
>> 213: String fileSystemSep = ((PathFileObject) file).getPath().getFileSystem().getSeparator();
>
> what about using: System.getProperty("file.separator")?
@vicente-romero-oracle Explaining a bit more ... on Windows, the default file system separator is `` but we're dealing here with `Path` objects from the "internal" JRT file system, which uses `/` as a separator. That's why we have to be careful to use the right separator. On Unix/Linux/macOS, the separators are the same, which is how the test has passed on those platforms.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2004
More information about the compiler-dev
mailing list