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.
The following code slide illustrates a problem which was detected when using FileSets.createFileObjectSet. The documentation states that a FileObject should be returned from the iterator (since keepBrokenLinks is false broken links would not persist). This is breaking a regression test in the compilation module. MutableFileSet mfs = FileSets.createFileObjectSet(false, ReferenceResolver.getDefault() ); mfs.add(aFileObject); Iterator it = mfs.iterator(); while (it.hasNext()) { Object fobj = it.next(); //fobj.getClass().equals(java.net.URL) // instead of FileObject }
Actually it is correct. The usage of FileSets API is pretty cryptic in this area. I think we should change it somehow, but you can remember simple rule for now. All instances of FileSet provide iterators which return URL when you call next(), no matter what kind of FileSet you have created. If you really want to have typed iterator (that one returning FileObject or DataObject) you have to use appropriate factory method which takes the fileset and returns java.util.Set. Then take iterator from that Set and you can safely typecast objects returned from this iterator's next() method. Please, don't confuse the two createFileObjectSet methods - first returning MutableFileSet and second returning java.util.Set. We talked already about this with jpokorsky and he had some idea about how to improve the API as I can remember. Adding keywords to make this issue more visible :-). Honzo, please, look at it.
The problem with the api here is that if I use the method returning Set then I no longer have the ordering guarantee, since java.util.Set does not guarantee ordering (java.util.List guarantee ordering), which violates the contract or will the supplied Set preserve ordering.
I think that returned Set will keep the ordering if source FileSet does. The Set delegates to the FileSet passed to the factory method which created this Set. In other words the Set is just another way how to access contents of the FileSet and its behavior is equivalent to the source FileSet IMO the javadoc describes poorly concepts of FileSets API, at least I would not guess this behavior without knowing the code. (E.g. javadoc says that createFileObjectSet(FileSet, boolean) returns immutable set of FileObjects acquired from the source FileSet. It's only partialy true, the Set can't be modified externally, but its contents can change when the source FileSet's contents changes.)
You have to use Set FileSets.createFileObjectSet(FileSet src, boolean brokenLinks) to obtain fileset's items as translated FileObject. And yes, the Set returned from FileSets.createXXXObjectSet keeps ordering of the original fileset. I can update the javadoc to mention keeping the ordering feature by the returned Set.
As described in http://www.netbeans.org/servlets/ReadMsg?msgId=619519&listName=nbdiscuss the current work on projects prototype has been stopped. Marking issue as VERIFIED --->
---> CLOSED