Skip to content

Modify FileUtil.toPath to never return null - #9820

Open
jtulach wants to merge 16 commits into
apache:masterfrom
jtulach:jtulach/FileObjectAndPath
Open

jtulach wants to merge 16 commits into
apache:masterfrom
jtulach:jtulach/FileObjectAndPath

Conversation

@jtulach

@jtulach jtulach commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor
  • in Made FileUtil to copy POSIX permissions #4654 @lkishalmi added FileUtil.toPath
    • however it works only for LocalFileSystem
  • I want to enhance it to work for any FileObject
  • e.g. change the method to never return null
  • create a shared test suite - done in 1e50301
  • use it in LocalFileSystemTest and make it pass - done in 1e50301
  • expand the test suite to cover more Path <-> FileObject interactions
    • this is kinda never ending task, so spell you wish of what shall be tested
  • use the same test suite for masterfs - in 9b03fd0 - they already pass
  • use the same test suite for other filesystems - done in 283aee0
  • make it all pass - fallback implementation provided in bc3c106
  • document the (behavioral) API change - done in 5319023
  • verify FileTypeDetector works in NetBeans applications and its classloaders

@jtulach jtulach self-assigned this Nov 21, 2026
@jtulach jtulach added the Platform [ci] enable platform tests (platform/*) label Nov 21, 2026
@jtulach
jtulach marked this pull request as draft November 21, 2026 19:56

@eppleton eppleton left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making toPath work for every FileObject sounds useful, and the shared PathTestHid suite is a good base. Some observations from reading the code and checking the JDK and bootstrap sources; I didn't build or run the PR.

Most of the points below share one root: every PathTestHid test derives all paths from a single toPath() call, and on the fallback (non-disk) side the suite currently only runs on JarFileSystem, which is read-only. So equality across separate toPath() calls, writable virtual filesystems (MemoryFileSystem, MultiFileSystem/layers) and watch events are not exercised yet. Your "other filesystems" checklist item would catch several of these.

On the API side: toPath on master is only used from tests, so the new "never null" contract shouldn't break anything in the repo, but platform applications may use null as "not on disk". An apichanges.xml entry and a spec version bump would make that visible (I see it's on your checklist).

import org.openide.filesystems.FileUtil;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service = FileTypeDetector.class, position = 100)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Files.probeContentType loads installed detectors with ServiceLoader.load(FileTypeDetector.class, ClassLoader.getSystemClassLoader()) (checked in the JDK 21 sources). In unit tests the module is on the system classpath, so this works. In the running IDE, openide.filesystems lives in platform/core and is loaded by MainImpl.BootClassLoader, not the system classloader, so I'd expect this detector never to be found there. Also, it's registered globally, so it would be asked about every Path in the JVM, not just the virtual ones; returning null early for non-NioPathForFileObject paths would keep it out of the way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Interesting observation
  • how do we want to address it?
  • shell we register such an implementation in openide.util.lookup or openide.util and ...
  • ... let the implementation delegate to all FileTypeDetectors found in the Lookup.getDefault()?

@jtulach jtulach changed the title More tests for existing FileUtil.toPath Modify FileUtil.toPath to never return null Nov 21, 2026
@jtulach
jtulach marked this pull request as ready for review November 21, 2026 22:10
@jtulach
jtulach requested a review from eppleton November 22, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Platform [ci] enable platform tests (platform/*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants