Why are you skipping empty lines in the user's message?

All indexes of lines up to the chosen insertion point of the Change-Id should be copied as-is.  Since split("\n") removed the \n characters, we have to add those back in between each element.  But that's it.