Return-Path: Delivered-To: apmail-db-jdo-dev-archive@www.apache.org Received: (qmail 83625 invoked from network); 24 Jun 2006 23:07:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 24 Jun 2006 23:07:07 -0000 Received: (qmail 34386 invoked by uid 500); 24 Jun 2006 23:07:06 -0000 Mailing-List: contact jdo-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jdo-dev@db.apache.org Delivered-To: mailing list jdo-dev@db.apache.org Received: (qmail 34375 invoked by uid 99); 24 Jun 2006 23:07:06 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 Jun 2006 16:07:06 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=MISSING_HEADERS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [192.18.42.249] (HELO nwkea-pix-1.sun.com) (192.18.42.249) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 24 Jun 2006 16:07:05 -0700 Received: from d1-sfbay-09.sun.com ([192.18.39.119]) by nwkea-pix-1.sun.com (8.13.6+Sun/8.12.9) with ESMTP id k5ON6eEJ028667 for ; Sat, 24 Jun 2006 16:06:41 -0700 (PDT) Received: from conversion-daemon.d1-sfbay-09.sun.com by d1-sfbay-09.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) id <0J1E0090103VH800@d1-sfbay-09.sun.com> (original mail from Craig.Russell@Sun.COM) for jdo-dev@db.apache.org; Sat, 24 Jun 2006 16:06:40 -0700 (PDT) Received: from [192.168.0.10] (c-24-6-172-77.hsd1.ca.comcast.net [24.6.172.77]) by d1-sfbay-09.sun.com (Sun Java System Messaging Server 6.2-4.02 (built Sep 9 2005)) with ESMTPSA id <0J1E00BLL0732X40@d1-sfbay-09.sun.com> for jdo-dev@db.apache.org; Sat, 24 Jun 2006 16:06:40 -0700 (PDT) Date: Sat, 24 Jun 2006 16:06:37 -0700 From: Craig L Russell Subject: Re: class loading issue when super class has reference to sub class In-reply-to: <002101c697e6$8bc25980$0400000a@ILANC> Sender: Craig.Russell@Sun.COM Cc: JDO Expert Group , Apache JDO project Message-id: MIME-version: 1.0 X-Mailer: Apple Mail (2.750) Content-type: multipart/signed; protocol="application/pkcs7-signature"; boundary=Apple-Mail-237--1062976809; micalg=sha1 X-Priority: 3 References: <1151183725.449dab6d6bcfa@webmail.jpox.org> <002101c697e6$8bc25980$0400000a@ILANC> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --Apple-Mail-237--1062976809 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Hi Ilan, On Jun 24, 2006, at 4:32 PM, Ilan Kirsh wrote: > Hi Erik, > > I remember similar problems with this enhanced method in the past > so I just checked your test with ObjectDB, but now it works well > with no exception. > > The code that is produced by the ObjectDB Enhancer is slightly > different > and instead of jdoFieldNames.length there is a constant that is > calculated > at enhancement time. Hopefully this change should do the difference. Please note that there is a difference between what the spec requires in terms of the semantics and what the sample code shows as an implementation. The sample code in 21.21 is not normative. The spec requires: protected static int jdoGetManagedFieldCount(); This method returns the number of managed fields declared by this class plus the number inherited from all superclasses. This method is generated in the class to allow the class to determine at runtime the number of inherited fields, without having introspection code in the enhanced class. The sample code for Employee in section 21.21 is: 21.21.7 Generated jdoGetManagedFieldCount The generated method returns the number of managed fields in this class plus the number of inherited managed fields. This method is expected to be executed only during class loading of the subclasses. The implementation for topmost classes in the hierarchy: protected static int jdoGetManagedFieldCount () { return jdoFieldNames.length; } The implementation for subclasses: protected static int jdoGetManagedFieldCount () { return .jdoGetManagedFieldCount() + jdoFieldNames.length; } So it looks like we could improve the example code by replacing the jdoFieldNames.length with an unnamed constant (which does not require that the jdoFieldNames field be initialized). Craig > > Regards, > > Ilan > > ----- Original Message ----- From: "Erik Bengtson" > To: ; > Sent: Saturday, June 24, 2006 11:15 PM > Subject: class loading issue when super class has reference to sub > class > > >> Hi, >> >> There is an issue when initialising a class when super class has >> reference to >> sub class >> (Cclass extending Bclass extending Aclass and Aclass has a >> reference to Cclass) >> >> public class Aclass { >> private Cclass cclass; >> } >> public class Bclass extends Aclass { >> } >> >> public class Cclass extends Bclass { >> } >> >> public class Main { >> public static void main(String[] args) throws Exception { >> //The following line throws ExceptionInInitializerError caused by >> java.lang.NullPointerException >> System.out.println(Class.forName("org.jpox.test.Bclass")); >> } >> } >> >> >> Exception in thread "main" java.lang.ExceptionInInitializerError >> at java.lang.Class.forName0(Native Method) >> at java.lang.Class.forName(Unknown Source) >> at org.jpox.test.Aclass.___jdo$loadClass(Aclass.java) >> at org.jpox.test.Aclass.__jdoFieldTypesInit(Aclass.java) >> at org.jpox.test.Aclass.(Aclass.java) >> at java.lang.Class.forName0(Native Method) >> at java.lang.Class.forName(Unknown Source) >> at org.jpox.test.Main.main(Main.java:6) >> Caused by: java.lang.NullPointerException >> at org.jpox.test.Bclass.jdoGetManagedFieldCount(Bclass.java) >> at org.jpox.test.Cclass.__jdoGetInheritedFieldCount(Cclass.java) >> at org.jpox.test.Cclass.(Cclass.java) >> ... 8 more >> >> >> See for a diagram >> http://www.jpox.org/servlet/jira/browse/ENHANCER-58 >> >> >> The issue is due to the implementation of the jdoGetManagedFieldCount >> >> The implementation for topmost classes in the hierarchy: >> protected static int jdoGetManagedFieldCount () { >> return jdoFieldNames.length; >> } >> The implementation for subclasses: >> protected static int jdoGetManagedFieldCount () { >> return .jdoGetManagedFieldCount() + >> jdoFieldNames.length; >> } >> >> > > Craig Russell Architect, Sun Java Enterprise System http://java.sun.com/products/jdo 408 276-5638 mailto:Craig.Russell@sun.com P.S. A good JDO? O, Gasp! --Apple-Mail-237--1062976809 Content-Transfer-Encoding: base64 Content-Type: application/pkcs7-signature; name=smime.p7s Content-Disposition: attachment; filename=smime.p7s MIAG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