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.

Bug 75035

Summary: Difficult and non-obvious way to get config files
Product: platform Reporter: _ tboudreau <tboudreau>
Component: FilesystemsAssignee: rmatous <rmatous>
Status: RESOLVED DUPLICATE    
Severity: blocker CC: jglick, jtulach, ttran
Priority: P3 Keywords: API, API_REVIEW_FAST, ARCH, USABILITY
Version: 5.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description _ tboudreau 2006-04-13 20:53:52 UTC
Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject("/foo") 
is long and incredibly non-obvious, especially now that there is no concept of 
a Repository in the UI.  For new API users, a simple call would be much more 
friendly.

I suggest the following:

public static FileObject FileUtil.getConfigurationFile(String path) {
   return Repository.getDefault().getDefaultFileSystem().getRoot
().getFileObject("path");
}

and if possible, deprecate Repository.
Comment 1 Jesse Glick 2006-04-13 21:06:41 UTC
Deprecating Repository is not a good idea; there are circumstances where you
need to get the default FileSystem directly, e.g. for listeners. Using
FileUtil.getConfigFile("").getFileSystem() is possible but odd.

The correct body is

return Repository.getDefault().getDefaultFileSystem().findResource(path);

or perhaps

FileObject fo = Repository.getDefault().getDefaultFileSystem().findResource(path);
if (fo != null) {
  return fo;
} else {
  throw new FileNotFoundException(path);
}

on the assumption that the file/folder is usually expected to exist and most
people will forget to null-check.
Comment 2 Jesse Glick 2007-05-15 21:06:54 UTC
Some use cases now obsoleted by Lookups.forPath, some not.
Comment 3 Jesse Glick 2007-05-15 21:07:36 UTC
Filed twice indeed.

*** This issue has been marked as a duplicate of 91534 ***