Avoid java.lang.IndexOutOfBoundsException: Invalid line index=-1 < 0
Apply diff according diff.tpe.