Search code examples
javaopenj9

Eclipse OpenJ9, -XX:+CompactStrings and Trademark symbol in Path name


I just noticed a strange issue with Eclipse OpenJ9 and -XX:+CompactStrings VM flag. I wonder whether this is a bug or simply my misunderstanding of something...?

Here's what happens:

After receiving a path from DirectoryStream, if the path has a trademark symbol (™) in it, the symbol will be converted to another character, quotation mark (").

This happens only if Compact Strings are enabled.

I am using the latest Eclipse OpenJ9 (v0.23.0) on Windows 10.

HotSpot apparently has Compact Strings enabled by default, and it does not have the same issue.

Here's sample code that should demonstrate the issue:

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();
        }
    }
}

Solution

  • Just following up that an issue was created over at the Eclipse OpenJ9 GitHub repo and this problem has been fixed in code. You can follow the entire conversation leading up to the fix here:

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