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 103554

Summary: getElements() returns empty result when ClassIndex obtained during intial scan
Product: java Reporter: Andrei Badea <abadea>
Component: SourceAssignee: Tomas Zezula <tzezula>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Bug Depends on:    
Bug Blocks: 95534    
Attachments: Project for reproducing the issue

Description Andrei Badea 2007-05-09 12:55:19 UTC
Run the following code for a FileObject owned by the attached project:

------%<-----
// FileObject fo

final ClasspathInfo cpi = ClasspathInfo.create(fo);
final ClassIndex index = cpi.getClassIndex();

JavaSource.create(cpi).runWhenScanFinished(new
CancellableTask<CompilationController>() {
    public void cancel() {
    }
    public void run(CompilationController controller) throws Exception {
        System.out.println("Finding usages");
        ElementHandle<TypeElement> entityHandle =
ElementHandle.create(controller.getElements().getTypeElement("javax.persistence.Entity"));
        for (ElementHandle<TypeElement> found : index.getElements(entityHandle,
EnumSet.of(SearchKind.TYPE_REFERENCES), EnumSet.of(SearchScope.SOURCE,
SearchScope.DEPENDENCIES))) {
            System.out.println("Found " + found);
        }
    }
}, true);
------%<-----

No "Found" lines will be printed. It starts working if you move the
"getClassIndex()" line inside the task.
Comment 1 Andrei Badea 2007-05-09 12:58:27 UTC
Created attachment 42240 [details]
Project for reproducing the issue
Comment 2 Tomas Zezula 2007-05-29 07:51:29 UTC

*** This issue has been marked as a duplicate of 104751 ***
Comment 3 Tomas Zezula 2007-05-30 12:28:12 UTC
Not exact duplicate, reopening.
Comment 4 Tomas Zezula 2007-07-03 09:25:06 UTC
Checking in src/org/netbeans/modules/java/source/usages/ClassIndexManager.java;
/cvs/java/source/src/org/netbeans/modules/java/source/usages/ClassIndexManager.java,v  <--  ClassIndexManager.java
new revision: 1.6; previous revision: 1.5
done