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 76606 - ClassDefinition.getMethod() does not work for methods with parameterized parameter
Summary: ClassDefinition.getMethod() does not work for methods with parameterized para...
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 5.x
Hardware: All All
: P3 blocker (vote)
Assignee: Pavel Flaska
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-19 13:58 UTC by Sanjeeb Sahoo
Modified: 2007-09-26 09:14 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 Sanjeeb Sahoo 2006-05-19 13:58:03 UTC
Opening this bug subsequent to my discussion with Pavel Flaska.

I have some code that tries to find out if for a given getter method, an
appropriate setter method exists or not? A getter method is of type *T getXXX()*.

If I find a non static method like *void setXXX(T t)* in the class, I consider
that to be the matching setter method. Code below does this. When I have a class
that has methods like these:

class Department {
   Collection<Employee> employees;
   public Collection<Employee> getEmployees() {
       return employees;
   }

   public void setEmployees(Collection<Engineer> employees) {
       // this.employees = employees; // won't work, hence commented
       for(Employee e : employees) {
           this.employees.add(e);
       }
   }
}

it returns setEmployees as the corresponding setter for getEmployees(). Is this
not incorrect, even when Engineer extends Employee?

My code exists in:
org.netbeans.modules.j2ee.verification.persistence.Introspector.class:
--------------------------------------------------------------------------------------
   public static Method getSetter(Method getter) {
       String setterName;
       final String getterName = getter.getName();
       if(getterName.startsWith(IS_PREFIX)) {
           setterName = SET_PREFIX +
                   getterName.substring(IS_PREFIX_SIZE);
       } else {
           setterName = SET_PREFIX +
                   getterName.substring(GET_PREFIX_SIZE);
       }

       tmpDbg(setterName);

       Method setter = getter.getDeclaringClass().getMethod(
               setterName,
               Arrays.asList(getter.getType()),
               true);

       if (setter!=null) {
           tmpDbg(setter.getType().getName());
           // check to see if it meets other requirements like
           // correct return type, nonstatic.
           if(setter.getType().getName().equals(Constants.VOID) &&
                   !Modifier.isStatic(setter.getModifiers())) {
               return setter;
           }
       }
       return null;
   }
Comment 1 _ sandipchitale 2006-08-26 21:42:13 UTC
FWIW:

Collection<Engineer> employees is not a subtype of Collection<Employee> even
when Engineer is subclass of Employee.

See: Generics and Subtyping (Section 3) in
http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

Sorry fop butting in.
Comment 2 Sanjeeb Sahoo 2006-09-05 07:14:51 UTC
Referring to the commnt made by sandipchitale:

That's precisely the point and hence the bug has been filed.
Comment 3 Jan Becicka 2006-10-26 16:27:09 UTC
Javacore module was replaced by Retouche infrastructure. This bug is not valid
in trunk any more.
Comment 4 Quality Engineering 2007-09-20 10:35:08 UTC
Reorganization of java component