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.

Bug 64708 - NPE from usages finder
Summary: NPE from usages finder
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-09-20 09:06 UTC by _ tboudreau
Modified: 2007-09-26 09:14 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
patch for java\navigation that illustrates the problem (3.18 KB, patch)
2005-09-20 09:27 UTC, _ tboudreau
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description _ tboudreau 2005-09-20 09:06:24 UTC
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)
Comment 1 _ tboudreau 2005-09-20 09:12:47 UTC
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.
Comment 2 Jan Becicka 2005-09-20 09:25:47 UTC
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.
Comment 3 _ tboudreau 2005-09-20 09:27:03 UTC
Created attachment 24963 [details]
patch for java\navigation that illustrates the problem
Comment 4 _ tboudreau 2005-09-20 10:04:43 UTC
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.
Comment 5 Jan Chalupa 2005-10-02 17:24:37 UTC
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.
Comment 6 _ tboudreau 2005-10-03 07:32:10 UTC
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.
Comment 7 Jan Becicka 2005-10-13 08:51:50 UTC
This exception cannot be triggered in a "normal" run of NetBeans.
Comment 8 Quality Engineering 2007-09-20 11:52:40 UTC
Reorganization of java component