Skip to content

Find usages shows no results #9685

Open

Description

@ezanstraenergq

Apache NetBeans version

Apache NetBeans 31

What happened

I've updated from Netbeans 28 to 31 and now I when I use 'find usages' on a (static) method it returns nothing, even when I can see the method is being used in the same class. Searching in the changelog I suspect the submit with hash: 8bd3ab8 might not be working properly, though when closing everything I might be able to use find usages again.

Language / Project Type / NetBeans Component

No response

How to reproduce

After a couple of 'find usage' commands it won't find anything anymore on a static method. Clearing the cache won't help, but after closing every window in Netbeans, closing Netbeans, clearing the cache and starting Netbeans again it works again - briefly.

Did this work correctly in an earlier version?

Apache NetBeans 28

Operating System

Windows 11

JDK

21

Apache NetBeans packaging

Apache NetBeans binary zip

Anything else

My colleague who runs Netbeans 31 on CachyOS experiences the same.

Are you willing to submit a pull request?

No

Activity

  1. mbien commented on Oct 9, 2026

    @mbien
    Member

    do you have a project where this can be reproduced?

  2. added
    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)
    pending-responseAwaiting further information to be supplied
    on Oct 9, 2026
  3. ezanstraenergq commented on Oct 9, 2026

    @ezanstraenergq
    Author

    It is a maven project and unfortunately I can't share it (it is proprietary); I can give you a slightly edited pom though:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.energq</groupId>
        <artifactId>testdummy</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.release>21</maven.compiler.release>
            <exec.mainClass>com.energq.testdummy.Main</exec.mainClass>
        </properties>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>3.5.6</version>
                    <configuration>
                        <excludes>
                            <exclude>**/tryout/**/*.java</exclude>
                        </excludes>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>assemble-all</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.5.0</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.energq.testdummy.Main</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>2.14.0</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>2.0.18</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-simple</artifactId>
                <version>2.0.18</version>
            </dependency>
            <dependency>
                <groupId>commons-io</groupId>
                <artifactId>commons-io</artifactId>
                <version>2.22.0</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.20.0</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>com.ghgande</groupId>
                <artifactId>j2mod</artifactId>
                <version>1.0</version>
            </dependency>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>EventRecording</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.neovisionaries</groupId>
                <artifactId>nv-websocket-client</artifactId>
                <version>2.14</version>
            </dependency>
            <dependency>
                <groupId>${project.groupId}</groupId>
                <artifactId>EnerGQCommon</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.hivemq</groupId>
                <artifactId>hivemq-mqtt-client</artifactId>
                <version>1.3.15</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.networknt</groupId>
                <artifactId>json-schema-validator</artifactId>
                <version>3.0.5</version>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>org.eclipse.paho</groupId>
                <artifactId>org.eclipse.paho.mqttv5.client</artifactId>
                <version>1.2.5</version>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </project>

    you can remove or replace the artifacts "EnerGQCommon" and "EventRecording" as these are other netbeans projects that I share with other projects. For a while I thought the problem was a wrong java version as the "maven.compiler.release" field was set to 26 instead of the 21 I have installed on my system. It really seems to be occurring when multiple 'usage' tabs are opened

  4. mbien commented on Oct 9, 2026

    @mbien
    Member

    a few more questions:
    is the project using the java module system?
    You mentioned static methods, does it work fine for everything else or was that a coincidence?
    Does anything appear in the log right when you run the find usages action?

  5. mbien commented on Oct 9, 2026

    @mbien
    Member

    my guess is that it is likely an indexing issue #4642, #4285

    esp since you mentioned that restarting the IDE fixes it. Restart causes the code scanner to refresh in case something changed.

  6. neilcsmith-net commented on Oct 9, 2026

    @neilcsmith-net
    Member

    Can you also confirm whether restricting the search to the current project works ok? Checking if it's the same issue I can reproduce.

  7. ezanstraenergq commented on Oct 12, 2026

    @ezanstraenergq
    Author

    6. my guess is that it is likely an indexing issue #4642, #4285
    esp since you mentioned that restarting the IDE fixes it. Restart causes the code scanner to refresh in case something changed.

    Closing the usages tabs and restarting the IDE fixes it, without closing these tabs the problem remained

  8. ezanstraenergq commented on Oct 12, 2026

    @ezanstraenergq
    Author

    7. Can you also confirm whether restricting the search to the current project works ok? Checking if it's the same issue I can reproduce.

    Restricting the search to the current project worked! And setting it back to open projects made it reoccur.
    -edit- That said, I have a few non-maven projects which can't easily be converted to maven because these depend on some finicky frameworks.

  9. removed
    needs:triageRequires attention from one of the committers
    pending-responseAwaiting further information to be supplied
    on Nov 13, 2026
  10. mbien commented on Nov 13, 2026

    @mbien
    Member

    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. -> #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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Java[ci] enable extra Java tests (java.completion, java.source.base, java.hints, refactoring.java, form)kind:bugBug report or fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions