Per upstream issue 296, each Junk should end whenever a new line begins with a single character that could be the start of a new Entry (i.e. ^[-#a-zA-Z]). This is working correctly only in the case of potential Comment entries (see comments.ftl where the leading # starts a new Junk) but is incorrect for all other cases such as possible Messages and Terms (see unclosed.ftl which should result in 4 Junks but instead merges 6 junk_lines into 1 Junk).
Note the JavaScript implementation has the same bug.