ModeShape/modeshape — pull request #1224 by rhauch (2014-08-27 17:14:33+00:00)
Title: MODE-2283 Corrected behavior when removing and then replacing strong reference props

When a reference value is changed, the `SessionNode` methods attempt to look for the special case where the new (transient) reference value matches that of the persisted value. IOW, given this code that sets up an initial persisted state:

```
Node referenceableNode = session.getRootNode().addNode("referenceable");
referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());

Node node1 = session.getRootNode().addNode("node1");
node1.setProperty("prop1", session.getValueFactory().createValue(referenceableNode, false));
session.save();
```

making the following changes transiently in the session:

```
node1.setProperty("prop1", session.getValueFactory().createValue(referenceableNode, false));
```

sets the property to the exact same value as persisted. `SessionNode` discovers this case and that this operation makes no net changes to the persisted content, so it alters the session's state to reflect this no-net-change.

Notice that the reported scenario is *close* to this, but it first removes the property before resetting it back to the same value:

```
node1.setProperty("prop1",(Value)null); // removes the property
node1.setProperty("prop1", session.getValueFactory().createValue(referenceableNode, false));
```
This is a special case that the `SessionNode` logic did not properly handle.

This PR corrects this behavior and adds a test case that replicated the problem before the fix is applied, and verifies the fix works.