users@jaxb.java.net

Re: Validate Error

From: Yuemin Wang <ywang_at_todo1.com>
Date: Mon, 02 Dec 2002 11:32:56 -0500

Hi Ed,

I have just downloaded the jaxb-1.0-beta and tried the same scenario, the
problem is still there.

Let me explain the problem more clearly:
As we all know that an element with '?' in XML DTD file means 0 or 1, i.e.
this element can be null or one. The correct validation logic for this
element should be:

        1. return OK -- if the element is empty ( == null)
        2. return v.validate(_XXX) -- if the element is not empty

But by using jaxb-1.0-ea or jaxb-1.0-beta to generate the java code, you
will find the validation logic only contain the second one. That means even
the DTD defined the element as '?' 0 or 1, but you if you ignore this
element the validation will through exception. This why each time after I
bind the java code from a DTD, I have to go through all the '?' elements
java code to modify the "validate" method, and add the first logic manually,
e.g.:

from:
> v.validate(_PAYINFO);

to:
> if ( _PAYINFO != null)
> v.validate(_PAYINFO);

Ed, If this is not clear, or my way to bind is not correct, please let me
know.

Thank you!

Yuemin Wang
ywang_at_todo1.com
786-331-0089


-----Original Message-----
From: Discussion list for the Java Architecture for XML Binding
[mailto:JAXB-INTEREST_at_JAVA.SUN.COM]On Behalf Of Ed Mooney
Sent: Monday, December 02, 2002 10:42 AM
To: JAXB-INTEREST_at_JAVA.SUN.COM
Subject: Re: Validate Error


Hi Yuemin,

jaxb-1.0-beta throws javax.xml.bind.ValidationException[1] if you try to
validate an instance containing an empty element whose schema requires
it not to be.

Regards,
--
Ed Mooney         |Sun Microsystems, Inc.|Time flies like
Java Web Services |UBUR02-201            |an arrow, but
Ed.Mooney_at_Sun.COM |1 Network Drive       |fruit flies like
781-442-0459      |Burlington, MA  01803 |a banana. Groucho
[1] http://java.sun.com/xml/jaxb/api/javax/xml/bind/ValidationException.html
Yuemin Wang wrote:
> Hi,
>
> I found a possible bug in jaxb-1.0-ea: "Validate
errorjava.lang.NullPointerException"
>
> This error happenes when validate option field (?) itself is an NESTED
element.
>
> Case one:
> ---------------------------------
> <!ELEMENT ALIMPRS (STATUS, CONFIRMNUM?, OPERCONFDT?)>
> <!ELEMENT CONFIRMNUM (#PCDATA) >
> <!ELEMENT OPERCONFDT (#PCDATA) >
>
> validation code:
>     public void validate(Validator v)
>         throws StructureValidationException
>     {
>         v.validate(_STATUS);
>     }
>
> ==> no problem! CONFIRMNUM and OPERCONFDT are simple ELEMENT
>
> Case two:
> ---------------------------------
> <!ELEMENT ALIMPRQ (USERINFO, ALTPROV*, PAYINFO?)>
> <!ELEMENT USERINFO EMPTY>
> <!ATTLIST USERINFO
>         USERID        CDATA #REQUIRED
>         USERPASS      CDATA #IMPLIED
>
> ...
> <!ELEMENT PAYINFO (ACCTINFO, AMOUNT) >
> <!ELEMENT AMOUNT (#PCDATA) >
>
> Validation Code:
>     public void validate(Validator v)
>         throws StructureValidationException
>     {
>         v.validate(_USERINFO);
>         for (Iterator i = _ALTPROV.iterator(); i.hasNext(); ) {
>             v.validate(((ValidatableObject) i.next()));
>         }
>         v.validate(_PAYINFO);
>     }
>
> ==> Problem: the PAYINFO is not allow 'null' ==> cause the error
> This happens when PAYINFO has nested ELEMENTS.
>
> The correct code for validate PAYINFO? shall be:
>
> if ( _PAYINFO != null)
>      v.validate(_PAYINFO);
>
> Don't know if this problem fix in the newest version?
>
> Thank you and happy holiday!
>
> Yuemin Wang