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 20511 - Problem with using an Identifier to find a ClassElement from a Source Element
Summary: Problem with using an Identifier to find a ClassElement from a Source Element
Status: CLOSED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: -FFJ-
Hardware: PC Windows ME/2000
: P3 blocker (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-02-13 15:42 UTC by Dana Kaufman
Modified: 2007-09-26 09:14 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Follow up e-mail from Sun with some additional information (1.26 KB, text/plain)
2002-02-13 15:44 UTC, Dana Kaufman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dana Kaufman 2002-02-13 15:42:56 UTC
I am going through this code I inherited and have found a section of that
does not appear to work correctly.  The code is taking a SourceDocument and
trying to find the main class using an Identifier.  I think the name it is
using with the Identifier is incorrect.  Here is the code, I have added
comments:

        ClassElement syncElement = null;
        Identifier id = Identifier.create(getName());  // getName() returns
a string "com.portfolio.Test1"

        SourceElement source = getSourceElementFromSourceFile(); //Returns a
valid SourceDocument
        Task task = source.prepare();
        task.waitFinished();

        /* This code I added for a check */
        ClassElement[] ce = source.getClasses();  //Only one class is return
which is correct
        for( int i=0; i<ce.length; i++){
           System.out.println("Found Class in
Source:"+ce[i].getSignature());  //Prints out "com/portfolio/Test1"
        }
        /* */

        System.out.println("Now trying to find id:"+id.getFullName() );
//Prints out "com.portfolio.Test1"
        syncElement = source.getClass(id);  //Always returns null!

The question is, what is the format of the String needed to be passed to the
create method of  the Identifier?  I think this line is bad:

        Identifier id = Identifier.create(getName());  // getName() returns
a string "com.portfolio.Test1"

it should be not with "." but with "/" like this:

        Identifier id = Identifier.create("com/portfolio/Test1");

>>Follow up, changing the "." to "/" didn't work as well
Comment 1 Dana Kaufman 2002-02-13 15:44:24 UTC
Created attachment 4689 [details]
Follow up e-mail from Sun with some additional information
Comment 2 Svata Dedic 2002-03-25 10:52:58 UTC
Aha. Now I understand what's going on: 
SourceElement.getClass() accepts either an unqualified 
identifier (Identifier.create("Test1") in your case), or 
a identifier matching exactly the class one 
(Identifier.create("com.portfolio.Test1", "Test1") in 
your example).
Your code passed the Identifier with full qualification 
but no source name (== the full one by default) and the 
element was not found.

I will add the possibility to lookup using canonical 
class name as well into the trunk; on released products, 
please use unqualified name search, which is guaranteed 
to work.

Comment 3 Svata Dedic 2002-03-25 14:38:25 UTC
Fixed in trunk:

/cvs/openide/src/org/openide/src/MemoryCollection.java,v  
<--  MemoryCollection.java
new revision: 1.27; previous revision: 1.26
/cvs/java/src/org/netbeans/modules/java/model/InnerClassCollection.java,v 
 <--  InnerClassCollection.java
new revision: 1.5; previous revision: 1.4
/cvs/java/src/org/netbeans/modules/java/model/TopClassCollection.java,v 
 <--  TopClassCollection.java
new revision: 1.6; previous revision: 1.5


Comment 4 pzajac 2003-08-18 18:01:22 UTC
Honza B, can you verify this issue? Thanks.
Comment 5 Jan Becicka 2003-08-19 15:37:07 UTC
Verified in NB 3.5
Comment 6 Quality Engineering 2007-09-20 10:54:58 UTC
Reorganization of java component