jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
castor
  • castor
  • CASTOR-2035

IDREF has no ID

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.1 M1, 1.1 M2, 1.1 M3, 1.1, 1.1.1, 1.1.2, 1.1.2.1, 1.2-SNAPSHOT, 1.2
  • Fix Version/s: 1.3.4
  • Component/s: XML
  • Labels:
    None
  • Environment:
    Win 32
  • Testcase included:
    yes
  • Number of attachments :
    4

Description

This error message is raised while serializing objects to XML : "The following exception occured while validating field: B of class: A: The object associated with IDREF "A@86b72583" of type class A has no ID!". Castor 1.0.5 is the last version, in which it works correctly.

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Hide
    Zip Archive
    CastorTest.zip
    03/Jul/07 2:00 AM
    4 kB
    Marek Lapak
    1. File
      CastorTest/.classpath 0.7 kB
    2. File
      CastorTest/.project 0.4 kB
    3. XML File
      CastorTest/build.xml 2 kB
    4. XML File
      CastorTest/castor-mapping.xml 0.8 kB
    5. File
      CastorTest/README 0.1 kB
    6. Java Source File
      CastorTest/src/bugs/xml/A.java 0.6 kB
    7. Java Source File
      CastorTest/src/bugs/xml/B.java 0.6 kB
    8. Java Source File
      CastorTest/src/bugs/xml/CastorTest.java 0.7 kB
    Download Zip
    Show
    Zip Archive
    CastorTest.zip
    03/Jul/07 2:00 AM
    4 kB
    Marek Lapak
  2. Text File
    patch.c2035.20070911.txt
    11/Sep/07 6:35 AM
    4 kB
    Werner Guttmann
  3. Text File
    patch.c2035.20070913.txt
    13/Sep/07 6:39 AM
    4 kB
    Matthias Epheser
  4. Text File
    patch.c2035.20080302.txt
    02/Mar/08 3:34 PM
    4 kB
    Werner Guttmann

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Werner Guttmann added a comment - 07/Jul/07 6:13 AM

Marek, did you realize that we improved validation of IDs/IDHREF attributes when switching to 1.1. and later releases. In other words, if your IDREF attribute points to an ID attribute (value) that does not exist, Castor (1.1. and above) will complain by throwing an exception.

Show
Werner Guttmann added a comment - 07/Jul/07 6:13 AM Marek, did you realize that we improved validation of IDs/IDHREF attributes when switching to 1.1. and later releases. In other words, if your IDREF attribute points to an ID attribute (value) that does not exist, Castor (1.1. and above) will complain by throwing an exception.
Hide
Permalink
Werner Guttmann added a comment - 07/Jul/07 1:21 PM

Well, actually, ignore above comment, as clearly your problem is related to marshalling only ...

Show
Werner Guttmann added a comment - 07/Jul/07 1:21 PM Well, actually, ignore above comment, as clearly your problem is related to marshalling only ...
Hide
Permalink
Werner Guttmann added a comment - 11/Sep/07 6:33 AM - edited

It looks like the problem is with the following code in IdRefValidator at lines 58ff:

        try {
            ClassDescriptorResolver classDescriptorResolver = context.getResolver();
            ClassDescriptor classDescriptor = classDescriptorResolver.resolve(object.getClass());
            FieldDescriptor fieldDescriptor = classDescriptor.getIdentity();
            FieldHandler fieldHandler = fieldDescriptor.getHandler();
            id = (String) fieldHandler.getValue(object);
        } catch (Exception e) {
            String err = "The object associated with IDREF \"" + object
            + "\" of type " + object.getClass() + " has no ID!";
            throw new ValidationException(err);
        }

There's a cast to java.util.String, which suggests that this won't work with your identities typed 'long'. Let me do some more investigations, though. For the time being, you could use the following property to skip id/href validation altogether:

#

  1. Property specifying whether id/href validation should be lenient;
  2. defaults to false
    org.exolab.castor.xml.lenient.id.validation=true
Show
Werner Guttmann added a comment - 11/Sep/07 6:33 AM - edited It looks like the problem is with the following code in IdRefValidator at lines 58ff: try { ClassDescriptorResolver classDescriptorResolver = context.getResolver(); ClassDescriptor classDescriptor = classDescriptorResolver.resolve(object.getClass()); FieldDescriptor fieldDescriptor = classDescriptor.getIdentity(); FieldHandler fieldHandler = fieldDescriptor.getHandler(); id = (String) fieldHandler.getValue(object); } catch (Exception e) { String err = "The object associated with IDREF \"" + object + "\" of type " + object.getClass() + " has no ID!"; throw new ValidationException(err); } There's a cast to java.util.String, which suggests that this won't work with your identities typed 'long'. Let me do some more investigations, though. For the time being, you could use the following property to skip id/href validation altogether: # Property specifying whether id/href validation should be lenient; defaults to false org.exolab.castor.xml.lenient.id.validation=true
Hide
Permalink
Werner Guttmann added a comment - 11/Sep/07 6:35 AM

JUnit test case relative to src/bugs to highlight the issue at hand.

Show
Werner Guttmann added a comment - 11/Sep/07 6:35 AM JUnit test case relative to src/bugs to highlight the issue at hand.
Hide
Permalink
Werner Guttmann added a comment - 12/Sep/07 5:32 AM

Marek, when working towards Castor 1.1 months ago, we decided to fix a couple issues related to mis-handling of IDs/IDHREFs, incl. duplicate IDS, missing IDs, etc. As a result of this work, we (not knowingly) committed ourselves to allow Strings for IDs only - as this is what the XML code generator produces for element definitions typed with <xs:ID>.

Question: would it be a problem for you to switch to String, or would you insist on seeing that being fixed, as it worked with Castor 1.0.5 and earlier ?

Show
Werner Guttmann added a comment - 12/Sep/07 5:32 AM Marek, when working towards Castor 1.1 months ago, we decided to fix a couple issues related to mis-handling of IDs/IDHREFs, incl. duplicate IDS, missing IDs, etc. As a result of this work, we (not knowingly) committed ourselves to allow Strings for IDs only - as this is what the XML code generator produces for element definitions typed with <xs:ID>. Question: would it be a problem for you to switch to String, or would you insist on seeing that being fixed, as it worked with Castor 1.0.5 and earlier ?
Hide
Permalink
Matthias Epheser added a comment - 13/Sep/07 6:34 AM

reposting my thoughts from dev-list:

I just debugged your junit test, and you are right, the cast to String is the problem in this particular case. But I don't think just chanching the String to Object in IDRefValidator does the trick.

I'm trying to get the big picture, let me just tell you my first unstructured thoughts, maybe we find a solution together:

  • the IDValidator is only used with XSId. XSId maps to java.lang.String. So the IDValidator extends StringValidator, it evens throws a validation exception if the given object is no string.

-the id*REF*validator just implements TypeValidator, as XSIDREF refers to java.lang.Object

  • looking at their behavior, it only makes sense to use them together: idrefvalidator puts unresolved ids into a collection, idvalidator takes occuring ids out of this collection. if the collections is empty in the end -> everything is fine
  • in our case - just marshalling with a mapping file, without descriptor classses - we have a strange situation: The XmlClassDescriptors describing the objects are created dynamicaly and they create the following:
  • Class A:
    FieldDescriptor for "aid" with a FieldValidator (no IDValidator)
  • Class B:
    FieldDescriptor for "aRef" with a FV WITH IDRefValidator

So attribute A.aId is treated as normal field (not as id), but B.aref is treated as IDREF.

  • But it makes no sense to use the idrefvalidator without a idvalidator. Being nosy, I changed the String cast in idrefvalidator into object, and our testcase succeeds. So the final "are-there-unreferenced-ids-left-check" is not performed.
Show
Matthias Epheser added a comment - 13/Sep/07 6:34 AM reposting my thoughts from dev-list: I just debugged your junit test, and you are right, the cast to String is the problem in this particular case. But I don't think just chanching the String to Object in IDRefValidator does the trick. I'm trying to get the big picture, let me just tell you my first unstructured thoughts, maybe we find a solution together: the IDValidator is only used with XSId. XSId maps to java.lang.String. So the IDValidator extends StringValidator, it evens throws a validation exception if the given object is no string. -the id*REF*validator just implements TypeValidator, as XSIDREF refers to java.lang.Object looking at their behavior, it only makes sense to use them together: idrefvalidator puts unresolved ids into a collection, idvalidator takes occuring ids out of this collection. if the collections is empty in the end -> everything is fine in our case - just marshalling with a mapping file, without descriptor classses - we have a strange situation: The XmlClassDescriptors describing the objects are created dynamicaly and they create the following: Class A: FieldDescriptor for "aid" with a FieldValidator (no IDValidator) Class B: FieldDescriptor for "aRef" with a FV WITH IDRefValidator So attribute A.aId is treated as normal field (not as id), but B.aref is treated as IDREF. But it makes no sense to use the idrefvalidator without a idvalidator. Being nosy, I changed the String cast in idrefvalidator into object, and our testcase succeeds. So the final "are-there-unreferenced-ids-left-check" is not performed.
Hide
Permalink
Matthias Epheser added a comment - 13/Sep/07 6:39 AM

patch for review:

  • adds the IDValidator to the FieldDescriptors for aid, bid
  • performs the "are-any-unresolved-ids-left" check in the validate method of the Marshaller
  • in order to get the xmlctf-suite run without problems, I also changed the cast

String value = (String) object; -> to String value = object.toString()

in IDValidator and IDRefValidator.

If this patch turns out to have no sideeffects, it adds validation of ids (Strings, or other objects with suitable toStribg-method) and idrefs to Marshalling.

Show
Matthias Epheser added a comment - 13/Sep/07 6:39 AM patch for review: adds the IDValidator to the FieldDescriptors for aid, bid performs the "are-any-unresolved-ids-left" check in the validate method of the Marshaller in order to get the xmlctf-suite run without problems, I also changed the cast String value = (String) object; -> to String value = object.toString() in IDValidator and IDRefValidator. If this patch turns out to have no sideeffects, it adds validation of ids (Strings, or other objects with suitable toStribg-method) and idrefs to Marshalling.
Hide
Permalink
Werner Guttmann added a comment - 14/Sep/07 5:39 AM

As a result of this, I think the new requirement for the toString() method on the identities needs to be exposed somewhere. Can you please try to find the right place in the user documentation ? In the worst case, you'll have to create a new page .. .

Show
Werner Guttmann added a comment - 14/Sep/07 5:39 AM As a result of this, I think the new requirement for the toString() method on the identities needs to be exposed somewhere. Can you please try to find the right place in the user documentation ? In the worst case, you'll have to create a new page .. .
Hide
Permalink
Werner Guttmann added a comment - 11/Dec/07 10:35 AM

Matthias ?

Show
Werner Guttmann added a comment - 11/Dec/07 10:35 AM Matthias ?
Hide
Permalink
Werner Guttmann added a comment - 02/Mar/08 3:34 PM

Updated patch, necessary after SVN move of all XML artifacts to the 'xml' module.

Show
Werner Guttmann added a comment - 02/Mar/08 3:34 PM Updated patch, necessary after SVN move of all XML artifacts to the 'xml' module.

People

  • Assignee:
    Werner Guttmann
    Reporter:
    Marek Lapak
Vote (2)
Watch (2)

Dates

  • Created:
    03/Jul/07 2:00 AM
    Updated:
    05/Mar/11 5:32 AM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.