MacOS file system changes between 7u10 and 7u40?
Xueming Shen
xueming.shen at oracle.com
Fri Sep 27 04:44:39 UTC 2013
What we did in 7130915 is to normalize the native macos file name (in
NFD) back into
NFC for the File and Path, but passing the File/Path Java path name (in
NFC) into macos's
file system API directly (as it appears those APIs just work fine with
NFC file name, though
it stores them in NFD internally). This serves the purpose of having
Java file name
(File and Path, and their String representation) in NFC form
consistently, cross all platforms.
As the consequence, we can have a reasonable implement of file name
equals() without
involving string normalization, which is expensive. In "normal" use
scenario, you should
not have a file/path name (in String) passing around in NFD form.
-Sherman
On 9/20/13 3:32 AM, Philippe Marschall wrote:
> Hi
>
> Have there been any changes to the way the default file system handles
> Unicode normalization between 7u10 and 7u40? I'm suddenly seeing code
> behave differently and I don't remember reading anything in the
> changelogs. I'm seeing two differences:
>
> First Path#toRealPath() return values seem to be NFC instead if NFD.
> This is a bit confusing because AFAIK MacOS stores in NFD. This code
> works in 7u10 but fails in 7u40
>
> FileSystem fileSystem = FileSystems.getDefault();
> String aUmlaut = "\u00C4";
> Path aPath = fileSystem.getPath(aUmlaut);
> String normalized = Normalizer.normalize(aUmlaut, Form.NFD);
> Path nPath = fileSystem.getPath(normalized);
>
> Path createdFile = null;
> try {
> createdFile = Files.createFile(aPath);
> assertEquals(1, createdFile.getFileName().toString().length());
> assertEquals(1,
> createdFile.toAbsolutePath().getFileName().toString().length());
> assertEquals(2,
> createdFile.toRealPath().getFileName().toString().length()); //
> failure is here
> } finally {
> if (createdFile != null) {
> Files.delete(createdFile);
> }
> }
>
> Second Path#equals now seems to normalize paths. This code works in
> 7u10 but fails in 7u40
>
> FileSystem fileSystem = FileSystems.getDefault();
> String aUmlaut = "\u00C4";
> String normalized = Normalizer.normalize(aUmlaut, Form.NFD);
> assertEquals(1, aUmlaut.length());
> assertEquals(2, normalized.length());
> Path aPath = fileSystem.getPath("/" + aUmlaut);
> Path nPath = fileSystem.getPath("/" + normalized);
> assertEquals(1, aPath.getName(0).toString().length());
> assertThat(aPath, not(equalTo(nPath)));
>
> Cheers
> Philippe
More information about the nio-dev
mailing list