jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Norman (JIRA)" <j...@apache.org>
Subject [jira] Created: (JCR-784) NodeType.canAddProperty(key, BinaryValue) consumes the InputStream making it unusable for setting the property
Date Sun, 11 Mar 2007 21:08:09 GMT
NodeType.canAddProperty(key, BinaryValue) consumes the InputStream making it unusable for setting
the property
--------------------------------------------------------------------------------------------------------------

                 Key: JCR-784
                 URL: https://issues.apache.org/jira/browse/JCR-784
             Project: Jackrabbit
          Issue Type: Bug
          Components: core
         Environment: Any
            Reporter: Eric Norman
            Priority: Minor


When checking if a binary property can be added to a given node type, the input stream inside
the BinaryValue object is consumed, making the subsequent call to setProperty(..) not work
because the stream has been positioned at the end of the input stream.

The stream is consumed by the following line in NodeTypeImpl.canSetProperty(..)

            // create InternalValue from Value and perform
            // type conversion as necessary
            InternalValue internalValue = InternalValue.create(value, targetType,
                    nsResolver);

The internalValue object becomes a BlobFileValue that consumes the input stream in it's constructor.

Expected:
The canAddProperty decision should be made without consuming the input stream in the Value
object.

Example Code:

Node targetNode; //get node from somewhere
InputStream inStream; //get instream from somewhere

String key = "propName"; //property key
Value value = session.getValueFactory().createValue(inStream);

NodeType nodeType = revisionNode.getPrimaryNodeType();
if (nodeType.canAddProperty(key, value)) {
    targetNode.setProperty(key, value);
}


Workaround:
Create a dummy value to do the canAddProperty check.

Value dummyValue = session.getValueFactory().createValue(session, new ByteArrayInputStream(new
byte[0]));
if (revisionNodeType.canSetProperty(key, dummyValue)) {
    revisionNode.setProperty(key, (Value)value);
}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message