0

我刚刚注意到 Eclipse OpenJ9 和-XX:+CompactStringsVM 标志的一个奇怪问题。我想知道这是一个错误还是只是我对某事的误解......?

这是发生的事情:

收到来自 的路径后DirectoryStream,如果路径中有商标符号(™),该符号将转换为另一个字符,引号(“)。

仅当启用紧凑字符串时才会发生这种情况。

我在 Windows 10 上使用最新的 Eclipse OpenJ9 (v0.23.0)。

HotSpot 显然默认启用了 Compact Strings,但它没有同样的问题。

这是应该演示该问题的示例代码:

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;

public class TrademarkSymbol {

    public static void main(String[] args) {

        // First, create the file Test™.txt somewhere

        Path path = Paths.get("C:\\test\\Test™.txt");

        // This works (the file exists):

        System.out.println(path + " exists? " + Files.exists(path, LinkOption.NOFOLLOW_LINKS));

        // However, now try to get the path via DirectoryStream:
        Path parent = path.getParent();
        try {

            DirectoryStream<Path> stream = Files.newDirectoryStream(parent);

            stream.forEach(it -> {

                // Here, the path no longer exists, because the trademark-symbol has been replaced with "-character.

                System.out.println(it + " exists? " + Files.exists(it, LinkOption.NOFOLLOW_LINKS));
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
4

1 回答 1

0

只是跟进在 Eclipse OpenJ9 GitHub 存储库中创建了一个问题,并且该问题已在代码中修复。您可以在此处关注导致修复的整个对话:

https://github.com/eclipse/openj9/issues/11650

于 2021-01-18T22:26:54.540 回答