You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Loris Bouzonnet (JIRA)" <ji...@apache.org> on 2008/08/24 13:09:44 UTC

[jira] Created: (FELIX-697) Generation of a duplicated field when using generics

Generation of a duplicated field when using generics
----------------------------------------------------

                 Key: FELIX-697
                 URL: https://issues.apache.org/jira/browse/FELIX-697
             Project: Felix
          Issue Type: Bug
          Components: iPOJO
    Affects Versions: iPOJO-0.8.0
         Environment: Felix 1.0.4
            Reporter: Loris Bouzonnet
         Attachments: ipojo-testcase.zip

Here an extract of my test case:

In an abstract Class AbsI, I have:

public abstract class AbsI<T extends Serializable> implements I {
[...]
    protected abstract T getName();

    public String getPlip() {
        return getName().toString();
    }
[...]
}
In a child A:
public class A extends AbsI<String> {
    protected String getName() {
        return "a";
    }
}

Generated code for A is:

public class A extends AbsI<String>
{
  private InstanceManager __IM;
  private boolean jdField___MgetName_of_type_Boolean;
  private boolean jdField___MgetName_of_type_Boolean;
[...]
}

=> jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Updated: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Clement Escoffier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Clement Escoffier updated FELIX-697:
------------------------------------

    Fix Version/s: iPOJO-1.0.0

> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>             Fix For: iPOJO-1.0.0
>
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Commented: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Clement Escoffier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12629506#action_12629506 ] 

Clement Escoffier commented on FELIX-697:
-----------------------------------------

So, this issue comes from an "unexpected" behavior of the compiler. In fact, the method 'getName' is duplicated in the bytecode. The only difference is the returned type (String against Serializable). So, the generated bytecode sounds like incorrect, but works anyway. Here is the generated class (decompiled)
    protected String getName() {
        return "a";
    }
    
    protected volatile Serializable getName() {
        return getName();
    }

This duplication comes from the generics. iPOJO has not expected this kind of code, and so generate twice the same identifier (based on the method name and the argument list). 
I will fix this issue by inserting the field only once. The two methods will then used the same flag. It makes sense as the two methods are associated (the generated one always call the written one).

PS : I don't know why the generated method becomes volatile.


> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Work started: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Clement Escoffier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Work on FELIX-697 started by Clement Escoffier.

> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Assigned: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Clement Escoffier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Clement Escoffier reassigned FELIX-697:
---------------------------------------

    Assignee: Clement Escoffier

> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Closed: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Loris Bouzonnet (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Loris Bouzonnet closed FELIX-697.
---------------------------------


Good. Thank you Clément!

> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Resolved: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Clement Escoffier (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Clement Escoffier resolved FELIX-697.
-------------------------------------

    Resolution: Fixed

Fixed in the revision 693520.
I commit a patch and add the test case in my test suite. 
Loris, could you confirm the fix?

> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Commented: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Clement Escoffier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12629531#action_12629531 ] 

Clement Escoffier commented on FELIX-697:
-----------------------------------------

Just an update,

This behavior requires Java 1.5. It also appears when implementing an interface and providing a method returning a subtype of the expected type such as in : 
 
public interface Foo {
    Object getFoo();
}

public class FooImpl implements Foo {
   public String getFoo() {
    return "foo";
   }
}

So, the compiled class will contain two getFoo method : one returning a String, and one returning an Object. The second one is generated by the compiler, and invokes the first 'written' one.


> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>            Assignee: Clement Escoffier
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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


[jira] Updated: (FELIX-697) Generation of a duplicated field when using generics

Posted by "Loris Bouzonnet (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/FELIX-697?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Loris Bouzonnet updated FELIX-697:
----------------------------------

    Attachment: ipojo-testcase.zip

The test-case

> Generation of a duplicated field when using generics
> ----------------------------------------------------
>
>                 Key: FELIX-697
>                 URL: https://issues.apache.org/jira/browse/FELIX-697
>             Project: Felix
>          Issue Type: Bug
>          Components: iPOJO
>    Affects Versions: iPOJO-0.8.0
>         Environment: Felix 1.0.4
>            Reporter: Loris Bouzonnet
>         Attachments: ipojo-testcase.zip
>
>
> Here an extract of my test case:
> In an abstract Class AbsI, I have:
> public abstract class AbsI<T extends Serializable> implements I {
> [...]
>     protected abstract T getName();
>     public String getPlip() {
>         return getName().toString();
>     }
> [...]
> }
> In a child A:
> public class A extends AbsI<String> {
>     protected String getName() {
>         return "a";
>     }
> }
> Generated code for A is:
> public class A extends AbsI<String>
> {
>   private InstanceManager __IM;
>   private boolean jdField___MgetName_of_type_Boolean;
>   private boolean jdField___MgetName_of_type_Boolean;
> [...]
> }
> => jdField___MgetName_of_type_Boolean is duplicated and cannot be loaded.

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