ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Benedict (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Commented: (IBATIS-128) Detect illegal overloaded JavaBeans properties methods (e.g. setters)
Date Sun, 13 May 2007 06:35:15 GMT

    [ https://issues.apache.org/jira/browse/IBATIS-128?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12495339
] 

Paul Benedict commented on IBATIS-128:
--------------------------------------

This fix has created an emergency blocker. The current solution assumes pre-Java 5 language
constructs, which are no longer valid with JDK 5. Here's a test case you can use to fix the
problem:

abstract class Entity<K> {
  public abstract K getId();
}

abstract class SimpleKeyEntity extends Entity<Long> {
  public abstract Long getId();
}

class ConcreteObject extends SimpleKeyEntity {
}

With generics (JDK 5+), you will get multiple signatures with the same function name. This
creates both "Object getId()" and "Long getId()" which is perfectly valid. The second version
is called a "bridge" method and is auto-generated by the compiler, which takes the specific
instance of the class and then calls the original.

You should be using a different algorithm to take this in account. If you find multiple signatures
and at least one is a bridge, use the bridge (call java.lang.reflect.Method.isBridge to determine).

I am dead in the water with iBATIS until this is fixed.

> Detect illegal overloaded JavaBeans properties methods (e.g. setters)
> ---------------------------------------------------------------------
>
>                 Key: IBATIS-128
>                 URL: https://issues.apache.org/jira/browse/IBATIS-128
>             Project: iBatis for Java
>          Issue Type: Improvement
>          Components: SQL Maps
>    Affects Versions: 2.0.8
>         Environment: iBatis 2.0.7
>            Reporter: Jerome Lacoste
>         Assigned To: Jeff Butler
>            Priority: Minor
>             Fix For: 2.2.0
>
>
> ClassInfo keys setters by their names.
> private void addMethods(Class cls) {
>     Method[] methods = cls.getMethods();
>     for (int i = 0; i < methods.length; i++) {
>       String name = methods[i].getName();
>       if (name.startsWith("set") && name.length() > 3) {
>         if (methods[i].getParameterTypes().length == 1) {
>           name = dropCase(name);
> -->        setMethods.put(name, methods[i]);
>           setTypes.put(name, methods[i].getParameterTypes()[0]);
>         }
> See http://cvs.sourceforge.net/viewcvs.py/ibatisdb/ibatis-dbl-2/src/com/ibatis/common/beans/ClassInfo.java?rev=1.8&view=markup
> So if you overload a method in your bean, you never know which one is going to be stored
last in the map.
> With:
>   public void setFeatureIDs(Set featureIDs) {
>     this.featureIDs = featureIDs;
>   }
>   public void setFeatureIDs(List featureIDs) {
>     this.featureIDs = new TreeSet(featureIDs);
>   }
> I end up with the following error:
> Error setting property 'setFeatureIDs(java.util.Set=[2] $Proxy4 implements interface
java.util.List)' of 'Part-20021'. Cause: java.lang.IllegalArgumentException: argument type
mismatch Caused by: java.lang.IllegalArgumentException: argument type mismatch];
> See issue IBATIS-127 for debugging

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message