You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by Craig L Russell <Cr...@Sun.COM> on 2006/03/08 00:54:44 UTC

Bug in JPOX parser NPE in constructor (CollectionMetaData.java:96)

Hi,

I think I've found the problem with the NPE in parsing the company  
package.jdo in which we define a <package...> <interface...>  
<property...> <collection...>.

While constructing the collection metadata, we try to get the package  
name. The top of the stack contains the property in which the  
collection element is defined. Property extends field so we look for  
the class metadata to get the package metadata. But the field  
metadata doesn't know that it can be in an interface; it only knows  
about being in a class or embedded metadata. An interface does know  
its package, so it's possible for the interface metadata to return  
the package, but an interface is an AbstractClass whereas the  
getClassMetadata method returns ClassMetadata. Possibilities: you  
could redefine getClassMetadata to return AbstractClassMetadata or  
have InterfaceMetadata inherit ClassMetadata.

Also, looking at the JPOX implementation of startElement and it  
appears that it's not supported for an element "property" to be part  
of element "class". Shouldn't there be an else if (parent instanceof  
ClassMetaData) clause here?

         // New property for this interface
         else if (qName.equals("property"))
         {
             MetaData parent = getStack();
             if (parent instanceof InterfaceMetaData)
             {
                 InterfaceMetaData intmd = (InterfaceMetaData)parent;
                 PropertyMetaData propmd = newPropertyObject(intmd,  
attrs);
                 intmd.addProperty(propmd);
                 pushStack(propmd);
             }
             else if (parent instanceof EmbeddedMetaData)
             {
                 EmbeddedMetaData emd = (EmbeddedMetaData)parent;
                 PropertyMetaData propmd = newPropertyObject(emd,  
attrs);
                 emd.addProperty(propmd);
                 pushStack(propmd);
             }

Hope this helps.

Craig

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!


Re: Bug in JPOX parser NPE in constructor (CollectionMetaData.java:96)

Posted by Erik Bengtson <er...@jpox.org>.
Craig,

Thanks. It's a good shoot, but sadly it will require a big round of bullets,
maybe a machine gun, to shot down the issue. We have to change the metadata
package around the classes FieldMetaData, PropertyMetaData, Interface and
Class, and all references to them in JPOX. As I told before, the support to
persistent interfaces has only been partially implemented.

To simplify the tree, I plan to have things like this
ClassMetadata extends AbstractClassMetaData
InterfaceMetadata extends AbstractClassMetaData
FieldMetaData extends PropertyMetadata

There are attributes specific to PropertyMetadata that does not exist in
FieldMetaData, so these attributes will raise something like UnsupportedBlaBla

Regards,

Quoting Craig L Russell <Cr...@Sun.COM>:

> Hi,
>
> I think I've found the problem with the NPE in parsing the company
> package.jdo in which we define a <package...> <interface...>
> <property...> <collection...>.
>
> While constructing the collection metadata, we try to get the package
> name. The top of the stack contains the property in which the
> collection element is defined. Property extends field so we look for
> the class metadata to get the package metadata. But the field
> metadata doesn't know that it can be in an interface; it only knows
> about being in a class or embedded metadata. An interface does know
> its package, so it's possible for the interface metadata to return
> the package, but an interface is an AbstractClass whereas the
> getClassMetadata method returns ClassMetadata. Possibilities: you
> could redefine getClassMetadata to return AbstractClassMetadata or
> have InterfaceMetadata inherit ClassMetadata.
>
> Also, looking at the JPOX implementation of startElement and it
> appears that it's not supported for an element "property" to be part
> of element "class". Shouldn't there be an else if (parent instanceof
> ClassMetaData) clause here?
>
>          // New property for this interface
>          else if (qName.equals("property"))
>          {
>              MetaData parent = getStack();
>              if (parent instanceof InterfaceMetaData)
>              {
>                  InterfaceMetaData intmd = (InterfaceMetaData)parent;
>                  PropertyMetaData propmd = newPropertyObject(intmd,
> attrs);
>                  intmd.addProperty(propmd);
>                  pushStack(propmd);
>              }
>              else if (parent instanceof EmbeddedMetaData)
>              {
>                  EmbeddedMetaData emd = (EmbeddedMetaData)parent;
>                  PropertyMetaData propmd = newPropertyObject(emd,
> attrs);
>                  emd.addProperty(propmd);
>                  pushStack(propmd);
>              }
>
> Hope this helps.
>
> Craig
>
> 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!
>
>