apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.67k stars 855 forks source link

Find usages not working #4285

Open TimeLord2004 opened 2 years ago

TimeLord2004 commented 2 years ago

Apache NetBeans version

Apache NetBeans 14

What happened

I have recently installed netbeans 14 (long time user of 8.1) and found the 'find usages' feature is not working in the following situation. Code (simplified) is like this:

public class MyJPanel extends JPanel
{
    protected static MyJPanel create()
    {
        return new MyJPanel();
    }
    private MyJPanel()
    {
    }
}

If I select find usages of the method create, netbeans reports zero usages; however I can manually navigate to the file that calls this create method. Is this because the method is static? Find usages seems to work for some other methods that I've checked (non-static). I don't know if it's just this scenario where it's broken or other places too, so I'm nervous about trusting the accuracy of the find usages feature. Update: I have discovered find usages not working also for some constructors (plain java objects, not static, not swing related).

How to reproduce

As per problem description. This feature used to work ok under netbeans 8.1.

Did this work correctly in an earlier version?

Apache NetBeans 12.3 or earlier

Operating System

Win 10 Pro

JDK

jdk1.8.0_111 32-bit (required as minimum supported version for our system)

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

Happens all the time.

Are you willing to submit a pull request?

No

Code of Conduct

Yes

JoachimRohde commented 2 years ago

This also happened to me two or three times in the past. Deleting the cache solved the problem for me.

TimeLord2004 commented 2 years ago

Something went wrong the first time I ran NB 14 and connected to my project and the advice for the error I was getting (can't remember now) was to clear cache. So already done that unfortunately. I've had to revert to NB 8.1 to get productive again, but I'd love it if someone had a solution to this problem under NB 14.

neilcsmith-net commented 2 years ago

Does changing the scope to just the project work? Do you have any projects using JPMS open?

eirikbakke commented 2 years ago

I've had this problem for years now, with indexing problems preventing Find Usages and Go to Symbol from finding all locations. The solution has been to delete the cache directory. I do remember it working perfectly in NetBeans 8.x (though perhaps this is correlated with the fact that I used Java 8 back then).

mbien commented 2 years ago

If I select find usages of the method create, netbeans reports zero usages; however I can manually navigate to the file that calls this create method.

how do you call this method? You didn't tell us the usage :)

jdk1.8.0_111 32-bit (required as minimum supported version for our system)

you aren't running netbeans on that, right? Thats for the project? You should run NetBeans on JDK 11+. You can use any JDK you want for your projects - thats two different settings.

If you believe this is a caching issue: close NetBeans. Clear the cache folder, start NetBeans and let it index everything.

this section in the readme explains how to find the cache location: https://github.com/apache/netbeans#log-config-and-cache-locations

BKBuEGmbH commented 2 years ago

Wouldn't it be a nice idea to have an menu entry to restart Netbeans and clear the cache?

I just had to clear the cache. The most time it consumed was to find a description for the solution of the problem. Perhaps a hint could be added to the "symbol not found" that a cache cleatr might help.

eirikbakke commented 1 year ago

I did some investigation regarding the "Go to Symbol" problems I mentioned earlier. That particular problem seems to be a separate problem that's actually at the dialog box implementation level, rather than at the indexer. (I instrumented the code and saw that all the right symbols were being returned from the indexer... they were just not being displayed in the dialog. Probably a race condition somewhere while waiting for results to be computed.) So not too relevant to the Find Usages problem reported here.

arturrataj commented 1 year ago

EDIT: It works for me now. Maybe only a problem with the build script.

TimeLord2004 commented 1 year ago

how do you call this method? You didn't tell us the usage :)

In my simple example, right-click on 'create()' and select 'Find Usages' from the popup menu.

you aren't running netbeans on that, right? Thats for the project? You should run NetBeans on JDK 11+

Maybe it's staring me in the face but I can't see where the min java requirement is specified. "You should run NetBeans on JDK 11+" - "should"? For efficiency for example? I notice you didn't write "must".

Thanks!

neilcsmith-net commented 1 year ago

Maybe it's staring me in the face but I can't see where the min java requirement is specified. "You should run NetBeans on JDK 11+" - "should"? For efficiency for example? I notice you didn't write "must".

https://netbeans.apache.org/download/nb16/#_deployment_platforms

JDK 11+ has been a requirement for running the IDE on since NetBeans 13. In fact, for Java editing since 12.6, although that hadn't been the intention.

mbien commented 1 year ago

its worth mentioning that NetBeans is able to run on the latest JDK at the time of the NB release. There are no good reasons to run it on anything lower than the latest LTS release, which would be JDK 17 right now.

janinko commented 1 year ago

I have also problem with Find Usages not working properly. I just updated from netbeans 12.2 to netbeans 17. I'm on Java: Java: 11.0.18; OpenJDK 64-Bit Server VM 11.0.18+10

Does changing the scope to just the project work? Do you have any projects using JPMS open?

Yes and yes. If I run "Find Usages" on a method with scope of current project, it finds usages in my project, if I run it with any higer scope, it does not find anythig.

If I run "Find Usages" on a class with scope of current project, it finds a lot of usages in my project, if I run it with any higer scope, it finds only two, on in current project and one in some different one.