lukehutch opened a new pull request, #9762: URL: https://github.com/apache/netbeans/pull/9762
(Comment added by Claude) Fixes #9761. `JarFileSystem.getTemporaryInputStream` copied every entry over 100000 bytes to one temporary file per (jar path hash, entry name hash), and returned a `FileInputStream` on it. While a `FileObject` of the filesystem is alive, every read copies the entry again, truncating that file while streams returned to earlier reads are still reading it. Concurrent reads therefore came back short. Two jars whose paths have the same hash code also shared the file, so a stream could return the other jar's entry. This change gives every read its own file from `Files.createTempFile` in the same `jarfscache<user.name>` directory, and opens it with `StandardOpenOption.DELETE_ON_CLOSE`. On Linux and macOS the file is unlinked as soon as it is opened. On Windows it is deleted when the stream is closed. `temporaryName`, the 10-second reuse, the `forceRecreate` parameter and `deleteOnExit` are removed. There is no extra copying in the common case, because the old code already made a new copy on every read while a `FileObject` was alive. Two tests are added to `JarFileSystemHidden`, which runs through `JarFileSystemTest`: - `testLargeEntriesOfJarsWithEqualPathHashesAreReadCorrectly` uses `Aa.jar` and `BB.jar`, whose paths have equal hash codes. It fails deterministically without the fix. - `testConcurrentReadsOfLargeEntry` makes 8 threads × 50 `asBytes()` calls on a 1 MB entry. I ran `JarFileSystemHidden` with the patched class ahead of the RELEASE310 jars on the classpath. I did not use the ant build. Results: | | Without the fix | With the fix | |---|---|---| | Linux, JDK 26, 8 runs | both new tests fail in every run | 7/7 pass in every run | | GitHub Actions JDK 21: ubuntu-latest, macos-latest, windows-latest, windows-2022, 3 runs each | both new tests fail | 7/7 pass, and no `jarfs*` files are left in `jarfscache` | A standalone stress test was also run on Linux: 16 threads × 500 reads of random 1 MB entries. It failed about 250 of 8000 reads without the fix and 0 with it. The one changed line without a functional change, the `jarCacheFolder` line, only loses trailing whitespace. Assisted-by: Claude Opus 5.5 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
