This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I came to this code while digging in this issue: https://netbeans.org/bugzilla/show_bug.cgi?id=268027 ("Performance issue: FileUtil.normalizedRef cache is cleaned too frequently") ... i just can't grasp why that lengthy way is really needed to get FileObject for a File : File#1 -> URI -> URL -> URI -> Path -> File#2 -> FileObject on this way of lookups && conversions File#1 and File#2 seems to be always equal (i.e. another instance will always point to the same file) and code finally always goes to FileBasedFileSystem.getFileObject(). So the question is - why just not skip all these CPU consuming actions and directly call FileBasedFileSystem.getFileObject(File)? I've implemeted this via dirty hack in local sources (see below) - nothing seems to get broken Below is full trail of this path in sources: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FileObject FileUtil.toFileObject(File file) : URL url = BaseUtilities.toURI(file).toURL(); retVal = URLMapper.findFileObject(url); -> URLMapper.getInstances().iterator() -> getFileObjects(url); -> FileObject[] FileBasedURLMapper.getFileObjects(): | | File file = FileUtil.normalizeFile(BaseUtilities.toFile(url.toURI())); | | -> File BaseUtilities.toFile(URI u) : | | Paths.get(u).toFile(); | | -> Path Paths.get(URI uri) | | for (FileSystemProvider provider: FileSystemProvider.installedProviders()) { | if (provider.getScheme().equalsIgnoreCase(scheme)) { | return provider.getPath(uri); | | -> sun.nio.fs.WindowsPath.toFile() | | return new File(toString()); | | FileObject fo = FileBasedFileSystem.getFileObject(file, FileObjectFactory.Caller.ToFileObject); | | -> FileObject FileBasedFileSystem.getFileObject(final File file, FileObjectFactory.Caller caller) { | ... Dirty hack: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - because FileBasedFileSystem is in 'Master Filesystem' and that module depends on 'File System API' where FileUtil.toFileObject(File file) is defined I've made a 'quick CDI' for that implementation: openide.filesystems\src\org\openide\filesystems\FileUtil.java public final class FileUtil extends Object { /* Injection point :) */ public static Function<File,FileObject> FileToFileObject; public static FileObject toFileObject(File file) { ... if( FileToFileObject != null ) { FileObject fo = FileToFileObject.apply(file); if( fo != null ) { return fo; } } masterfs\src\org\netbeans\modules\masterfs\filebasedfs\FileBasedFileSystem.java public class FileBasedFileSystem extends FileSystem { static { /* Injection of implementation :) */ FileUtil.FileToFileObject = (file) -> getFileObject(file, FileObjectFactory.Caller.ToFileObject); } public static FileObject getFileObject(final File file, FileObjectFactory.Caller caller) { ... }