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 49179 - CCE from ClassDefinition
Summary: CCE from ClassDefinition
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 4.x
Hardware: All All
: P3 blocker (vote)
Assignee: issues@java
URL:
Keywords: API
Depends on:
Blocks:
 
Reported: 2004-09-17 04:10 UTC by _ tboudreau
Modified: 2009-10-01 14:50 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ tboudreau 2004-09-17 04:10:47 UTC
I'm working on updating the Navigator module to use the new 
java API.  One thing I need to test:  If a method is overridden 
(you can right click a superclass node, and there's an Override 
action).

Maybe I'm not doing it correctly, but I had the following 
problem:

m = a Method declared in a superclass
target = a JavaClass I want to see if it's implemented on

the following code causes the exception:
return target.getMethod(m.getName(), m.getParameters(), false) 
!= null;

(testing for the CCE actually works to determine if it's 
overridden, but it's probably not supposed to work that way)


java.lang.ClassCastException
        at 
org.netbeans.modules.javacore.jmiimpl.javamodel.ClassDefinitio
nImpl.argTypesMatch(ClassDefinitionImpl.java:372)
        at 
org.netbeans.modules.javacore.jmiimpl.javamodel.ClassDefinitio
nImpl.getMethod(ClassDefinitionImpl.java:317)
        at 
org.netbeans.modules.javacore.jmiimpl.javamodel.ClassDefinitio
nImpl.getMethod(ClassDefinitionImpl.java:261)
        at 
org.netbeans.modules.javacore.jmiimpl.javamodel.JavaClassImpl
.getMethod(JavaClassImpl.java:386)
        at 
org.netbeans.jmi.javamodel.JavaClass$Impl.getMethod(Unknown 
Source)
        at 
org.netbeans.modules.javagator.JUtils$OverrideAction.alreadyOv
erridden(JUtils.java:747)
        at 
org.netbeans.modules.javagator.JUtils$OverrideAction.isEnabled(
JUtils.java:737)
Comment 1 Jan Becicka 2004-09-17 07:21:33 UTC
Yes, you are not doing it correctly. :)))

Fix your code this way:
List params = new ArrayList();
for (Iterator i = m.getParameters().iterator();
i.hasNext();params.add(((Parameter)i.next()).getType()));

return target.getMethod(m.getName(), params, false) != null;
Comment 2 _ tboudreau 2004-09-17 10:45:58 UTC
Erm, sorry to reopen, but the getParameters() returns an instance of java.util.List, and the 
workaround suggested is to create another java.util.List with the same contents.  It's an 
API usability thing - nobody is going to expect that one list will fail, but the other will 
succeed - to the API consumer they're both just vanilla java.util.List's.

Couldn't the code that gets called check the class of the list, and if it's not java.util.*, do 
this itself?  I think when external people start writing modules to this API they'll have a 
hard time figuring out why using the list they got from getParameters() won't work, but a 
new ArrayList with the same contents will (I know why, but I'm not worried about me, I'm 
worried about people complaining about how hard it is to write modules for NetBeans).  

We've already got enough hard-to-use stuff in our APIs, we shouldn't torture people with 
more, and this ought to be easy enough to fix (even if the actual list class used isn't visible 
to the code that gets called, you can still check if it's not ArrayList or LinkedList, and 
create a new list if so - or implement clone() on the custom list class to do something like 
that).

Thanks for the info, though - I'll fix my code to use it.
Comment 3 Jan Becicka 2004-09-17 13:12:55 UTC
It is not List with the same contents.
Method.getParameters() returns List of Parameters, while the new list
"params" is List of Types.
Comment 4 _ tboudreau 2004-09-18 10:06:32 UTC
Duh! [slapping myself on forehead]

Well, it still would be nice to make the comparison painless, but what I did shouldn't work.
Comment 5 Quality Engineering 2007-09-20 11:51:38 UTC
Reorganization of java component
Comment 6 Marian Mirilovic 2009-10-01 14:48:15 UTC
reopen to fix status and resolution
Comment 7 Marian Mirilovic 2009-10-01 14:50:50 UTC
fix status and resolution