MODE-1978 Corrected the WritableSessionCache to fix NPE from recently-added code

A recent fix for MODE-1940 added code that updated the indexes if the
new parent was persisted (previously) and the child was moved. In some
cases when the new parent was not persisted in a previous save but instead
was created as part of this save, the code resulted in an NPE. The fix
was a simple change.

A test case was added to first replicate the problem. After the change,
the test now succeeds (and the S-RAMP build works completely).