5 Replies Latest reply on Apr 8, 2011 12:03 PM by rhauch

    Value constraint violation handling

    dimonv

      Hi all,

       

      I have defined value constraints for the node properties in the node definition e.g.:

      - 'org:gender'  (String) mandatory < 'male', 'female'

       

      but on importing the an xml file containing wrong value:

        • an exception javax.jcr.nodetype.ConstraintViolationException is thrown but its message says that the property definition cannot be found "Cannot find a definition for the property named 'org:gender' on the node at ..." instead of which constraint is violated
        • this exception is caught then by org.modeshape.jcr.JcrContentHandler.BasicNodeHandler.create() and encapsulated  into org.modeshape.jcr.JcrContentHandler.EnclosingSAXException

       

      The JCR client has to catch EnclosingSAXException and then extract the cause (javax.jcr.nodetype.ConstraintViolationException) whose message is not very helpful.

      I understand that org.modeshape.jcr.JcrContentHandler extends SAX' DefaultHandler but anyway it would be useful for a JCR client to know the real cause.

      Doesn't it make sense to change this exception handling?

        • 1. Value constraint violation handling
          rhauch
            • an exception javax.jcr.nodetype.ConstraintViolationException is thrown but its message says that the property definition cannot be found "Cannot find a definition for the property named 'org:gender' on the node at ..." instead of which constraint is violated

          When ModeShape does not find an appropriate property definition, it doesn't really try to figure out if there is one with the same name but an incompatible type or constraint. It's not always easy to figure out what property definition "should apply", but in this case we should figure it out and report a more useful message. Feel free to log an enhancement request.

           

            • this exception is caught then by org.modeshape.jcr.JcrContentHandler.BasicNodeHandler.create() and encapsulated  into org.modeshape.jcr.JcrContentHandler.EnclosingSAXException

           

          The JCR client has to catch EnclosingSAXException and then extract the cause (javax.jcr.nodetype.ConstraintViolationException) whose message is not very helpful.

          I understand that org.modeshape.jcr.JcrContentHandler extends SAX' DefaultHandler but anyway it would be useful for a JCR client to know the real cause.

          Doesn't it make sense to change this exception handling?

           

          Yes, that's definitely not very useful. We should be unwrapping it. Please log a separate issue for this.

           

          Thanks!

          • 2. Value constraint violation handling
            rhauch

            Thanks for logging MODE-1138 and MODE-1139, Dmitri!

            • 3. Value constraint violation handling
              dimonv

              You're welcome, Randall.

              • 4. Value constraint violation handling
                rhauch

                Dmitri:

                 

                Can you provide a code sample of how you're importing, and a stack trace of the exception? If you're using Session.importXML(...), then our implementation should already be unwrapping the EnclosingSAXException and throwing the wrapped ConstraintViolationException, VersionException, or ItemExistsException. (It may be possible we're doubly-wrapping an exception, in which case we'll only unwrap once. But I doubt this is the case.)

                 

                I've added test cases that use Session.importXML to import XML files that contain values that will violate constraints, and with both system and document views I get a ConstraintViolationException upon import.

                 

                Note that if you're using the ContentHandler returned by Session.getImportContentHandler(), then you should get a SAXException, as the ConstraintViolationExceptions are not on the ContentHandler method signatures.

                • 5. Value constraint violation handling
                  rhauch

                  I've marked MODE-1139 as 'Cannot Reproduce Bug'. Feel free to reopen the issue if you can provide more information.