This is incorrect and will introduce a bug. If the targets.getUseSpecVersion() is not blank (move to the else condition) it's already been populated in the entity message, and the current logic will override it.

Do this instead. Break up the first if condition. If targets is null then go ahead and create the targets object. After that check if use spec version is blank.