Discussion:
ValidationException when the elements of an array are null
(too old to reply)
Yaldiz, Sunay
2004-02-04 13:47:04 UTC
Permalink
Hello,

I got such an exception when I try to marshall an array which is
created, but whose elements are null. I of course have the validation
property of the my marshaller set to true.
I tried similar thing by marshalling with an object whose reference was
null. This object was not of type collection. I thought I would get
validation exception also here, but I did not.
So, my question is, why do I get exception in the first case, but not in
the second? Actually what I want is that even if I want the marshalling
validated, I don't really want to get an exception because the array
elements are null. Is it possible?

Regards,
Sunay


The exception given is:

ValidationException: Cannot validate a null Object.;
- location of error: XPATH: test
at org.exolab.castor.xml.Validator.validate(Validator.java:97)
at
org.exolab.castor.xml.FieldValidator.validate(FieldValidator.java:233)
at
org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescr
iptorImpl.java:885)
at org.exolab.castor.xml.Validator.validate(Validator.java:122)
at org.exolab.castor.xml.Marshaller.validate(Marshaller.java:1890)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:763)
....
...



This e-mail contains confidential information for the exclusive attention of the intended addressee. Any access of third parties to this e-mail is unauthorised. Any use of this e-mail by unintended recipients such as copying, distribution, disclosure etc. is prohibited and may be unlawful. When addressed to our clients the content of this e-mail is subject to the General Terms and Conditions of GL's Group of Companies applicable at the date of this e-mail.

GL's Group of Companies does not warrant and/or guarantee that this message at the moment of receipt is authentic, correct and its communication free of errors, interruption etc.
Stein M. Hugubakken
2004-02-05 07:08:22 UTC
Permalink
Post by Yaldiz, Sunay
Hello,
I got such an exception when I try to marshall an array which is
created, but whose elements are null. I of course have the validation
property of the my marshaller set to true.
I tried similar thing by marshalling with an object whose reference was
null. This object was not of type collection. I thought I would get
validation exception also here, but I did not.
So, my question is, why do I get exception in the first case, but not in
the second? Actually what I want is that even if I want the marshalling
validated, I don't really want to get an exception because the array
elements are null. Is it possible?
It seems the problem is in FieldValidator.validate(Object object,
ValidationContext context):
...
if (type.isArray()) {
byteArray = (type.getComponentType() == Byte.TYPE);
if (!byteArray) {
size = Array.getLength(value);
if (_validator != null) {
for (int i = 0; i < size; i++)
_validator.validate(Array.get(value, i),
context);
}
else {
for (int i = 0; i < size; i++)
super.validate(Array.get(value, i), context);
}
}
}


Perhaps it's possible to override the validator, but someone else has to
comment on that.

You can patch the code and/or submit a bug-report on
http://bugzilla.exolab.org.

Stein

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
***@exolab.org with a subject of:
unsubscribe castor-dev

Loading...