You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Neeme Praks <ne...@apache.org> on 2003/05/15 00:29:43 UTC

[betwixt] [patch] lazy initialization bug in ElementDescriptor

The *bug*: when a user specifies the ID attribute in beaninfo file, then 
the attribute declaration is ignored on the first bean and respected on 
all the following beans.
Example .betwixt file:
<info>
    <element name="Language">
        <attribute name="id" property="id"/>
        <addDefaults/>
    </element>
</info>

The *cause*? The method XMLBeanInfo.findIDAttribute() uses 
getElementDescriptor().hasAttributes() method to find out if the element 
has any attributes defined. This method makes the following check:
    return attributeDescriptors != null && attributeDescriptors.length > 0;
Everything would be ok, if the attributeDescriptors field wouldn't be 
lazily initialized (in getAttributeDescriptors() method). So, the fix is 
to change the check to use this method instead.
Also, similar issue with hasChildren() and hasContent() methods, but I'm 
not sure if they would result in similar bugs. I fixed them also, just 
in case.

Patch attached.

Rgds,
Neeme

Re: [betwixt] [patch] lazy initialization bug in ElementDescriptor

Posted by robert burrell donkin <ro...@blueyonder.co.uk>.
committed. many thanks.

- robert

On Wednesday, May 14, 2003, at 11:29 PM, Neeme Praks wrote:

>
> The *bug*: when a user specifies the ID attribute in beaninfo file, then 
> the attribute declaration is ignored on the first bean and respected on 
> all the following beans.
> Example .betwixt file:
> <info>
>    <element name="Language">
>        <attribute name="id" property="id"/>
>        <addDefaults/>
>    </element>
> </info>
>
> The *cause*? The method XMLBeanInfo.findIDAttribute() uses 
> getElementDescriptor().hasAttributes() method to find out if the element 
> has any attributes defined. This method makes the following check:
>    return attributeDescriptors != null && attributeDescriptors.length > 0;
> Everything would be ok, if the attributeDescriptors field wouldn't be 
> lazily initialized (in getAttributeDescriptors() method). So, the fix is 
> to change the check to use this method instead.
> Also, similar issue with hasChildren() and hasContent() methods, but I'm 
> not sure if they would result in similar bugs. I fixed them also, just in 
> case.
>
> Patch attached.
>
> Rgds,
> Neeme
> Index: src/java/org/apache/commons/betwixt/ElementDescriptor.java
> ===================================================================
> RCS file: /home/cvspublic/jakarta-
> commons/betwixt/src/java/org/apache/commons/betwixt/ElementDescriptor.java,
> v
> retrieving revision 1.8
> diff -u -r1.8 ElementDescriptor.java
> --- src/java/org/apache/commons/betwixt/ElementDescriptor.java	19 Mar 2003 
> 22:59:01 -0000	1.8
> +++ src/java/org/apache/commons/betwixt/ElementDescriptor.java	14 May 2003 
> 22:15:05 -0000
> @@ -168,7 +168,7 @@
>       * @see #getElementDescriptors
>       */
>      public boolean hasChildren() {
> -        return elementDescriptors != null && elementDescriptors.length > 
> 0;
> +        return getElementDescriptors().length > 0;
>      }
>
>      /**
> @@ -177,7 +177,7 @@
>       * @see #getAttributeDescriptors
>       */
>      public boolean hasAttributes() {
> -        return attributeDescriptors != null && 
> attributeDescriptors.length > 0;
> +        return getAttributeDescriptors().length > 0;
>      }
>
>      /**
> @@ -186,7 +186,7 @@
>       * @see #getContentDescriptors
>       */
>      public boolean hasContent() {
> -        return contentDescriptors != null && contentDescriptors.length > 
> 0;
> +        return getContentDescriptors().length > 0;
>       }
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org