--- a/project.ant/src/org/netbeans/spi/project/support/ant/SourcesHelper.java +++ a/project.ant/src/org/netbeans/spi/project/support/ant/SourcesHelper.java @@ -711,8 +711,7 @@ * Register all external source or non-source roots using {@link FileOwnerQuery#markExternalOwner}. *

* Only roots added by {@link #addPrincipalSourceRoot} and {@link #addNonSourceRoot} - * are considered. They are registered if (and only if) they in fact fall - * outside of the project directory, and of course only if the folders really + * are considered. They are registered only if the folders really * exist on disk. Currently it is not defined when this file existence check * is done (e.g. when this method is first called, or periodically) or whether * folders which are created subsequently will be registered, so project type @@ -761,8 +760,7 @@ * Register all external source or non-source roots using {@link FileOwnerQuery#markExternalOwner}. *

* Only roots added by {@link #addPrincipalSourceRoot} and {@link #addNonSourceRoot} - * are considered. They are registered if (and only if) they in fact fall - * outside of the project directory, and of course only if the folders really + * are considered. They are registered only if the folders really * exist on disk. Currently it is not defined when this file existence check * is done (e.g. when this method is first called, or periodically) or whether * folders which are created subsequently will be registered, so project type @@ -836,14 +834,10 @@ // up calling APH.resolveFileObject repeatedly (for each property change) for (Root r : allRoots) { for (FileObject loc : r.getIncludeRoots(minimalSubfolders)) { - if (FileUtil.getRelativePath(pdir, loc) != null) { - // Inside projdir already. Skip it. - continue; - } if (loc.isFolder()) { try { Project other = ProjectManager.getDefault().findProject(loc); - if (other != null) { + if (other != null && other != p) { // This is a foreign project; we cannot own it. Skip it. continue; } --- a/projectapi/src/org/netbeans/modules/projectapi/SimpleFileOwnerQueryImplementation.java +++ a/projectapi/src/org/netbeans/modules/projectapi/SimpleFileOwnerQueryImplementation.java @@ -142,8 +142,9 @@ } } + URI key = fileObject2URI(f); if (!externalOwners.isEmpty() && (folder || externalRootsIncludeNonFolders)) { - Reference externalOwnersReference = externalOwners.get(fileObject2URI(f)); + Reference externalOwnersReference = externalOwners.get(key); if (externalOwnersReference != null) { FileObject externalOwner = externalOwnersReference.get(); @@ -166,16 +167,20 @@ } } if (!deserializedExternalOwners.isEmpty() && (folder || externalRootsIncludeNonFolders)) { - FileObject externalOwner = deserializedExternalOwners.get(fileObject2URI(f)); + FileObject externalOwner = deserializedExternalOwners.get(key); if (externalOwner != null && externalOwner.isValid()) { try { - // Note: will be null if there is no such project. Project p = ProjectManager.getDefault().findProject(externalOwner); - synchronized (this) { - lastFoundKey = new WeakReference(f); - lastFoundValue = new WeakReference(p); + if (p == null) { + // Now-deleted project, remove from list. + deserializedExternalOwners.remove(key); + } else { + synchronized (this) { + lastFoundKey = new WeakReference(f); + lastFoundValue = new WeakReference(p); + } + return p; } - return p; } catch (IOException e) { // There is a project there, but we cannot load it... LOG.log(Level.FINE, "Cannot load project.", e); //NOI18N