added null check for
ClassInstance.replaceAllOccurrencesOfReferredObject()