mbien commented on issue #9685: URL: https://github.com/apache/netbeans/issues/9685#issuecomment-6841530166
I could reproduce it. Even after IDE restart but had no time to investigate. So i zipped the config and cache to analyze it later. Today I extracted it and it was still reproducible. Find usages with file scope did work, open-project scope didn't. Problem was that both code paths were the exact same so I used an agent to instrument values on the whole path. 5 runs later the divergence point was found - like in a git bisection I suppose, just with log files and application state. Fix is a one-liner. Bug age is pre-apache. Haven't really tracked it beyond that. -> https://github.com/apache/netbeans/pull/9801 Specific scopes were not the root cause btw, in my reproducer the only scope which worked was current-file. (larger scopes made it more likely though) generated summary: <details> # Find Usages misses results with the “Open Projects” scope ## Symptom Find Usages in a Maven project returned no results with the **Open Projects** scope, while **Current File** seemed to work. ## Root cause `SourcePath.FR`, the wrapper behind `ClasspathInfo`’s source path, kept a source root in the search path only if `JavaIndex.hasSourceCache(root, true)` returned `true`. This check required both of the following: 1. The root’s usages index had to be visible through the persistent-only lookup in `ClassIndexManager`. This lookup ignored `transientInstances`, where lazily created indices are stored. 2. The index had to be in `State.INITIALIZED`. That state is reached only when the background indexer processes the root in the current session and calls `CacheAttributesTransaction.commit()`. In a fresh session, the on-disk index may already be up to date. The indexer then short-circuits with “New or modified files: 0,” so it does not process the root or promote its index from `NEW` to `INITIALIZED`. As a result, the root fails the `SourcePath.FR` check—even though `ClassIndex.createQueriesForRoots`, the actual query builder, would query it. The query builder calls `ClassIndexManager.getUsagesQuery(root, true)`, which can see transient indices. The source root was therefore silently removed from the search path, leaving sources-only scopes with nothing to query. ## Why the scopes behaved differently The issue was caused by the index’s state in the current session, not by the scope itself. | | Good state | Bad state | |---|---|---| | Where the index lives | `ClassIndexManager.instances` (persistent) | `transientInstances` (created lazily when the project loads) | | Index state | `INITIALIZED` | `NEW` | | How it happens | The background indexer processes the root—for example, because the index database is missing or rebuilt, a file was edited or created, or a build ran. | The session starts with an up-to-date on-disk index. The indexer reports “New or modified files: 0” and skips processing, so no `CacheAttributesTransaction.commit()` promotes the index. | | Result with the old filter | The root passes the filter. | The root fails the filter and is silently dropped from the search path. | **Current File** need only the refactored file’s own root, so they appeared to work when that root happened to be in the good state. **Open Projects** includes roots from other open projects, making it more likely that one of them is in the bad state—and causing that scope to fail first. In a bad-state session, all scopes are affected. To reproduce this, start the IDE, make no changes to the project, and run Find Usages with **Current Project**; it also returns no results. ## Fix In `SourcePath.FR.getRoots()`, use the weaker `hasSourceCache(root, false)` check. It recognizes usages queries for transiently created indices and does not require `State.INITIALIZED`, so the filter is consistent with the indices the query builder actually uses. </details> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
