Apache JDO Project - JPOX enhancer bug

This is Interesting: Free IT Magazines  
Home > Archive > Apache JDO Project > August 2005 > JPOX enhancer bug





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author JPOX enhancer bug
Michael Watzek

2005-08-10, 5:45 pm

Hi Andy,

I'm investigating JDO-100 ("Insert request failed ... because it would
have caused a duplicate key value").

The duplicate key exception is thrown because there is an exception in a
previous run during teardown preventing to delete the instance in the
datastore.

That exception is a NoSuchMethodError thrown by the enhanced code (see
below) of a class "PCPointSingleFieldDate" in methods
"jdoCopyKeyFieldsFromObjectId". I decompiled the code of that class. It
seems that the JPOX enhancer generates a java.util.Date constructor call
that does not exist. This is an excerpt of the decompiled code:

protected void jdoCopyKeyFieldsFromObjectId(Object oid)
{
if(!(oid instanceof ObjectIdentity))
{
throw new ClassCastException("key class is not
javax.jdo.identity.ObjectIdentity or null");
} else
{
ObjectIdentity o = (ObjectIdentity)oid;
id = new Date(o.getKey());
return;
}
}

Regards,
Michael

[java]
testSingleFieldIdentityInitializedDate(o
rg.apache.jdo.tck.api.persistencecapable.NewObjectIdInstance)javax
..jdo.JDOFatalException: Exception during tearDown
[java] at org.apache.jdo.tck.JDO_Test.tearDown(JDO_Test.java:281)
[java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:211)
[java] at
org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:128)
[java] at
org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:106)
[java] NestedThrowablesStackTrace:
[java] java.lang.NoSuchMethodError:
java.util.Date.<init>(Ljava/lang/Object;)V
[java] at
org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldDate.jdoCopyKeyFieldsFromObjectId(PCPoint
SingleFieldDate.java)
[java] at
org.apache.jdo.tck.pc.singlefieldidentity.PCPointSingleFieldDate.jdoNewInstance(PCPointSingleFieldDat
e.java)
[java] at
javax.jdo.spi.JDOImplHelper.newInstance(JDOImplHelper.java:199)
[java] at
org.jpox.state.StateManagerImpl.<init>(StateManagerImpl.java:340)
[java] at
org.jpox.AbstractPersistenceManager. getObjectById(AbstractPersistenceManager
.java:2322)
[java] at
org.jpox.AbstractPersistenceManager. getObjectById(AbstractPersistenceManager
.java:2230)
[java] at
org.apache.jdo.tck.JDO_Test.deleteTearDownInstances(JDO_Test.java:336)
[java] at
org.apache.jdo.tck.JDO_Test.localTearDown(JDO_Test.java:292)
[java] at org.apache.jdo.tck.JDO_Test.tearDown(JDO_Test.java:263)
[java] at org.apache.jdo.tck.JDO_Test.runBare(JDO_Test.java:211)
[java] at
org.apache.jdo.tck.util.BatchTestRunner.start(BatchTestRunner.java:128)
[java] at
org.apache.jdo.tck.util.BatchTestRunner.main(BatchTestRunner.java:106)
--
-------------------------------------------------------------------
Michael Watzek Tech@Spree Engineering GmbH
mailto:mwa.tech@spree.de Buelowstr. 66
Tel.: ++49/30/235 520 36 10783 Berlin - Germany
Fax.: ++49/30/217 520 12 http://www.spree.de/
-------------------------------------------------------------------

Andy Jefferson

2005-08-10, 5:45 pm

> That exception is a NoSuchMethodError thrown by the enhanced code (see
> below) of a class "PCPointSingleFieldDate" in methods
> "jdoCopyKeyFieldsFromObjectId". I decompiled the code of that class. It
> seems that the JPOX enhancer generates a java.util.Date constructor call
> that does not exist. This is an excerpt of the decompiled code:


Already known about.
Sadly the enhancer can't just put a call in to Craig's JDOImplHelper method to
construct a date (since it needs AccessPriveleged adding to the enhanced
classes etc, and since that has implications on enhancement). If that
JDOImplHelper method was just a static call then it would be easy to do, but
it isn't.

--
Andy

Craig Russell

2005-08-10, 5:45 pm

Craig Russell

2005-08-10, 5:45 pm

Andy Jefferson

2005-08-10, 5:45 pm

> I've patched the JDOImplHelper class to make the construct method
> static. There are no issues that I can think of to make this method
> static, so I'll change this.
>
> Does this help?


Hi Craig,

Thanks for looking into it. Referring to Michael's mail of the added=20
jdoCopyKeyFieldsFromObjectId() method, the error is at the end where it nee=
ds=20
to create a Date (or Locale, or Currency, or whatever) from the "oid". Is=20
construct() doing this ? or is it doing the reverse (I remember scanning=20
through it when you added ObjectIdentity and seeing the sort of parsing I=20
need to create an object from the oid, but may have been mistaken).

protected void jdoCopyKeyFieldsFromObjectId(Object oid)
=A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0if(!(oid instanceof ObjectIdentity))
=A0 =A0 =A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0 =A0 =A0throw new ClassCastException("key class is not =
=20
javax.jdo.identity.ObjectIdentity or null");
=A0 =A0 =A0 =A0 =A0} else
=A0 =A0 =A0 =A0 =A0{
=A0 =A0 =A0 =A0 =A0 =A0 =A0ObjectIdentity o =3D (ObjectIdentity)oid;
=A0 =A0 =A0 =A0 =A0 =A0 =A0id =3D new Date(o.getKey());
=A0 =A0 =A0 =A0 =A0 =A0 =A0return;
=A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0}

=2D-=20
Andy

Craig Russell

2005-08-10, 5:45 pm

Andy Jefferson

2005-08-11, 7:45 am

Hi Craig,

> I should have noticed this earlier. There already is a proper Date in
> the ObjectIdentity oid instance and all you need to do is to get it
> and cast it.


I should have noticed that one earlier too, much earlier :-)
Enhancer "jdoCopyKeyFieldsFromObjectId" methods are now fixed in CVS (will be
in build on 12/08/2005)

--
Andy

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com