[ 
https://issues.apache.org/jira/browse/OPENJPA-383?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Janko Heilgeist updated OPENJPA-383:
------------------------------------

    Attachment: enh_overloading_fix.patch

The newer version 1.14.0 of serp does mention the problem in the javadoc of 
getDeclaredMethod and offers a version of getDeclaredMethod, that takes as an 
additional parameter the return-type of a function to make the returned result 
unique. This patch updates the pom.xml to use 1.14.0 of serp and modifies 
PCEnhancer.java to use the new getDeclaredMethod with name, return-type and 
parameter-types.

This should definitely NOT be included into the SVN before Abe has had a good 
look at the patch. PCEnhancer.java is nothing for the faint-hearted and I am 
not sure, whether my patch has any side-effects or even solves the problem 
completely and correctly ;)

> Enhancement may cause corruption of classes using method overloading
> --------------------------------------------------------------------
>
>                 Key: OPENJPA-383
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-383
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 1.0.0, 1.0.1, 1.1.0
>         Environment: Java 1.5.0_12, Java 1.6.0_02
>            Reporter: Janko Heilgeist
>         Attachments: enh_overloading_fix.patch, enh_overloading_unittest.patch
>
>
> As already reported on the developers mailing-list, the enhancement of 
> classes that use method overloading may corrupt these classes. An example:
> public interface GenericEntity<PK extends Serializable> {
>         PK getEntityId();
>         void setEntityId(PK entityId);
> }
> public interface LongObjIdEntity extends GenericEntity<Long> {
>         Long getEntityId();
>         void setEntityId(Long entityId);
> }
> @Entity
> public class SomeEntity implements LongObjIdEntity {
>         private Long entityId;
>         @Id
>         @GeneratedValue
>         public Long getEntityId() { return entityId; }
>         public void setEntityId(Long entityId) { this.entityId = entityId; }
> }
> After enhancement of the class SomeEntity, calls to 
> SomeEntity.class.getDeclaredFields() may fail with an VerifyError due to a 
> "Wrong return type in function" getEntityId. This is a serious error because 
> getDeclaredFields() is called for example during the deserialization of 
> objects from an ObjectInputStream (which prohibits e.g. usage of such an 
> enhanced entity as argument to an EJB-function) and even in the PCEnhancer 
> class itself, which will fail when analyizing a previously enhanced class.
> The cause of this error is in my opinion related to bugs OPENJPA-251 and 
> OPENJPA-329. Reflection on the class returns two versions of the 
> getEntityId()-function: "Serializable getEntityId()" and "Long 
> getEntityId()". The enhancer uses a version of the function 
> getDeclaredMethod() of the serp-library, that does not guarantee which of 
> these methods is returned, if only the name of the function and its 
> parameter-types are specified. If the wrong method is picked, the enhanced 
> class is no longer usable.

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

Reply via email to