This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I'm working on fixing the usage matching functionality in java/navigation to use UsagesFinder correctly (seems to be much slower than fetching all the occurances of a string and then testing each one, but sometimes I get really weird results for what element is actually at that location, like a huge statement block, or some element that doesn't even start/end across the location I'm requesting). Anyway, the following code in UsagesFinder sometimes throws an NPE: if (m.signatureEquals((Method) what)) { ClassDefinition collectedClass, declaringClass = getRealClassDefinition(m.getDeclaringClass()); for (Iterator i = declaringClasses.iterator(); i.hasNext();) { ^^^^^^^^^^^^^^^^ declaringClasses is sometimes null, for whatever reason. java.lang.NullPointerException at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.isMatch(UsageFinder.java:211) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:164) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:167) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:167) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:167) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:167) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:167) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.getUsers(UsageFinder.java:149) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder.access$200(UsageFinder.java:36) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder$LazyIterator.findNext(UsageFinder.java:306) at org.netbeans.modules.javacore.jmiimpl.javamodel.UsageFinder$LazyIterator.hasNext(UsageFinder.java:336) at org.netbeans.modules.java.navigation.jmi.Hacks.findUsagesOfElement(Hacks.java:96) at org.netbeans.modules.java.navigation.ClassMemberRelatedItemProvider.collectRelatedItems(ClassMemberRelatedItemProvider.java:67) at org.netbeans.modules.java.navigation.spi.RelatedItemProviderSupport$Updater.run(RelatedItemProviderSupport.java:258) at org.openide.util.Task.run(Task.java:207)
100% reliable way to reproduce: Check out jnn sources: cvs co -d:pserver:USER@cvs.dev.java.net:/cvs jnn Calling UsagesFinder to find usages of the method show() in that class will always produce an NPE - i.e. NamedElement showMethod = //find the element UsageFinder uf = new UsageFinder (showMethod); uf.getUsers (new Resource[] { showMethod.getResource() }); will throw it.
UsageFinder is not API class, you use it at your own risk. You should not use it at all. Anyway - it looks like you created instance of UsageFinder for Callable Feature with incorrect constructor. Use constructor with 4 parameters for Callable Features.
Created attachment 24963 [details] patch for java\navigation that illustrates the problem
I know it's use at my own risk, I just wasn't sure if it was a real problem you guys didn't know about. I'll try the other constructor. What I'd really like to figure out is why, if I find all the locations in the document where "getFoo" occurs, why calling getElementAtOffset for some cases returns to me a giant StatementBlock, or the entire class, or other weirdness - finding all the string occurances of what I want to look for, and then just checking if each one is a VariableAccess/MethodInvocation of my method is way faster than UsagesFinder anyway.
Tim's last question seems to be about the java model support, not about java/navigation. Reading all the comments, I'm not sure this should be tracked as a defect at all.
If the javacore guys are satisfied that the code path that causes the NPE will never be triggered in a "normal" run of NetBeans, then, sure, close it. My code isn't passing any nulls, so it does look like something is broken somewhere in UsagesFinder. Up to you guys.
This exception cannot be triggered in a "normal" run of NetBeans.
Reorganization of java component