You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Janko Heilgeist (JIRA)" <ji...@apache.org> on 2007/09/25 10:48:50 UTC
[jira] Created: (OPENJPA-383) Enhancement may cause corruption of
classes using method overloading
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
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.
[jira] Updated: (OPENJPA-383) Enhancement may cause corruption of
classes using method overloading
Posted by "Janko Heilgeist (JIRA)" <ji...@apache.org>.
[ 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_unittest.patch
Unit-test that fails with release 1.0.0 and the current SVN version.
As the bug is related to some undeterministic behavior the unittest is not guaranteed to fail. The version with generics reliably failed on my computer. The alternative with a simple interface should fail to, if this bug is indeed related to OPENJPA-251 and OPENJPA-329, but it did not fail on my computer.
I did forget to mention in the bug-report, that the error only occurs, if the access-type is PROPERTY (whether due to putting the annotations on the getter or the access-type="PROPERTY" attribute in the orm.xml). This unit-test uses FIELD and PROPERTY access to test both cases.
> 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_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.
[jira] Updated: (OPENJPA-383) Enhancement may cause corruption of
classes using method overloading
Posted by "Janko Heilgeist (JIRA)" <ji...@apache.org>.
[ 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.