[java] fix infinite undo