Skip to content

refreshIndex when a file without project is opened - #9622

Open
JaroslavTulach wants to merge 2 commits into
apache:masterfrom
jtulach:jtulach/RefreshIndexForSingleFile
Open

JaroslavTulach wants to merge 2 commits into
apache:masterfrom
jtulach:jtulach/RefreshIndexForSingleFile

Conversation

@JaroslavTulach

Copy link
Copy Markdown
  • while working on ProjectsRootNode I found following error:
errors in Java source file
  • there are errors in the source code of ProjectsRootNode even there shall be none
    • the problem is that there is no open project
    • then the system doesn't create Index for ide/projectui/src and then it cannot find co-located files
  • @lahodaj suggested to use
    private static final boolean NO_SOURCE_FILTER = Boolean.getBoolean("SourcePath.no.source.filter"); //NOI18N
  • with -J-DSourcePath.no.source.filter=true it all works correctly
    • however Jan warns, that such a change could hurt IDE performance
  • as such I was seeking for another fix
  • explicitly refresh the index when it is not yet initialized

@jtulach jtulach self-assigned this Sep 16, 2026
@jtulach jtulach added the Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form) label Sep 16, 2026
@JaroslavTulach

Copy link
Copy Markdown
Author
  • this change does not create any new indexes
  • it only detects that there is a not yet initialized index and refreshes it
  • as such putting a file into $HOME doesn't make any difference, @lahodaj - there is no index, so we don't referesh it
no index for single file sources

@lahodaj lahodaj 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.

So, I dag deep(er), a this is what I've found:

starting from a clean userdir:

  • I go to Tools/Plugins and manually enable "Developing NetBeans" (we'll get to this later)
  • then I open ide/projectui/src/org/netbeans/modules/project/ui/ProjectsRootNode.java. There's indexing happening. No errors
  • then I restart the IDE
  • there are errors in ProjectsRootNode.java

The reason for this behavior is that there is:
https://github.com/apache/netbeans/blob/master/java/java.source.base/src/org/netbeans/modules/java/source/classpath/SourcePathCheck.java
which registers "unknown" roots. But, it uses !JavaIndex.hasSourceCache(url,false) (

), and as a consequence the registration only happens if there's no index whatsoever. I.e. it happens on the first run, but after the restart, the index does exist, and the registration is skipped.

This is what the patch here helps with; but it would be IMO hopefully cleaner to use !JavaIndex.hasSourceCache(url,true) instead.

This is, of course, only partial solution - and maybe, for your case, this partial solution is OK, then please go ahead with the false -> true change.

The limitations is that there needs to exist a project for the file (the very next line is FileOwnerQuery.getOwner(url.toURI()) != null). Hence:

  • if I don't go the Tools/Plugins and don't enable apisupport, there's no project for the file, and everything is red. For me, at least. Because this is a projectless source root now.
  • if I copy e.g. openide.util.lookup/src into a directory (without the project metadata), and open a file from this directory, I still see the errors. There no project and hence no index created by SourcePathCheck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Java [ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants