ppkarwasz commented on code in PR #781: URL: https://github.com/apache/commons-io/pull/781#discussion_r2337909930
########## src/test/java/org/apache/commons/io/FileSystemTest.java: ########## @@ -128,6 +190,42 @@ void testSorted() { } } + @Test + void testMaxNameLength_MatchesRealSystem(@TempDir Path tempDir) { + final FileSystem fs = FileSystem.getCurrent(); + final String[] validNames; + switch (fs) { + case MAC_OSX: + case LINUX: + validNames = new String[] { FILE_NAME_255_ASCII, FILE_NAME_255_UTF8_BYTES }; + break; + case WINDOWS: + validNames = new String[] { FILE_NAME_255_ASCII, FILE_NAME_255_UTF16_CODE_UNITS}; + break; + default: + throw new IllegalStateException("Unexpected value: " + fs); + } + for (final String fileName : validNames) { + assertDoesNotThrow(() -> testFileName(tempDir, fileName), "OS accepts max length name"); + assertTrue(fs.isLegalFileName(fileName, UTF_8), "Commons IO accepts max length name"); + final String tooLongName = fileName + "a"; + assertThrows(IOException.class, () -> testFileName(tempDir, tooLongName), "OS rejects too-long name"); + assertFalse(fs.isLegalFileName(tooLongName, UTF_8), "Commons IO rejects too-long name"); + } + } Review Comment: @garydgregory, Could you run this test on a MacOS with an APFS file system? MacOS is a little bit of a mystery to me: - File access in Java is implemented using the POSIX API, so the limits are measured in UTF-8 bytes. - HFS+ has a limit in UTF-16 code points. - While the POSIX specification does not require calls to fail if the file name length is greater than `NAME_MAX`, the behavior is undefined. MacOS apparently allows the usage of more than 255 UTF-8 bytes if the underlying file system supports it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org