You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Eric Norman (JIRA)" <ji...@apache.org> on 2007/03/11 22:08:09 UTC

[jira] Created: (JCR-784) NodeType.canAddProperty(key, BinaryValue) consumes the InputStream making it unusable for setting the property

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.


[jira] Updated: (JCR-784) NodeType.canSetProperty(keyString, Value) consumes the InputStream making it unusable for setting the property

Posted by "Stefan Guggisberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Guggisberg updated JCR-784:
----------------------------------

    Component/s:     (was: core)
                 nodetype

> NodeType.canSetProperty(keyString, Value) 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: nodetype
>    Affects Versions: 1.2.3
>         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.


[jira] Updated: (JCR-784) NodeType.canSetProperty(keyString, Value) consumes the InputStream making it unusable for setting the property

Posted by "Stefan Guggisberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Guggisberg updated JCR-784:
----------------------------------

    Summary: NodeType.canSetProperty(keyString, Value) consumes the InputStream making it unusable for setting the property  (was: NodeType.canAddProperty(key, BinaryValue) consumes the InputStream making it unusable for setting the property)

> NodeType.canSetProperty(keyString, Value) 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
>    Affects Versions: 1.2.3
>         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.


[jira] Resolved: (JCR-784) NodeType.canSetProperty(keyString, Value) consumes the InputStream making it unusable for setting the property

Posted by "Stefan Guggisberg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Guggisberg resolved JCR-784.
-----------------------------------

    Resolution: Invalid

eric, thanks for reporting this issue and providing a detailed description.

however, i don't agree with your analysis. according to the jsr 170 spec, 
NodeType.canSetProperty "returns true if setting propertyName to value 
is allowed by this node type." since a property defined in a node type can
specify value constraints (e.g. length of binary value, regular expressions
for string values, etc) and such value constraints need to be checked
by NodeType.canSetProperty, a passed stream unfortunately needs to
be materialized in order to verify that the value constraint(s) are satisfied.

i resolved this issue as 'invalid' since the current behavior is IMO 
compliant with the spec and therefore not a bug.

while i agree that NodeType.canSetProperty consuming a binary value is
somewhat irritating you shouldn't need to call this method in most situations. 
actually the only reasonable use case i can think of is providing feedback in a 
responsive gui editor, e.g. for validity checking while the user enters text. 







> NodeType.canSetProperty(keyString, Value) 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: nodetype
>    Affects Versions: 1.2.3
>         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.


[jira] Updated: (JCR-784) NodeType.canAddProperty(key, BinaryValue) consumes the InputStream making it unusable for setting the property

Posted by "Eric Norman (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/JCR-784?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Eric Norman updated JCR-784:
----------------------------

    Affects Version/s: 1.2.3

> 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
>    Affects Versions: 1.2.3
>         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.