@Test
public void testGroupCountAndMore_UNEXPECTED_notMatchingGroupsAfterEndOfTargetGroupIncluded() throws Exception {

    String input = "1xxnnnnnnnnnn";
    String regex = "(1xx(2yy)?)(3zz)?";
    Matcher matcher = Pattern.compile(regex).matcher(input);
    assertTrue(matcher.find());
    assertEquals(3, matcher.groupCount()); // principle of the longest possible match
    {
        // offset = 1 -> "1xx" will be the match result
        MatchResultWithOffset mo = new MatchResultWithOffset(matcher, 1);
        assertGroup(-1, "1xx", 0, 3, mo);
        assertGroup(0, "1xx", 0, 3, mo);
        assertGroup(1, null, -1, -1, mo); // group "(2yy)?"
        assertGroup(2, null, -1, -1, mo); // group "(3yy)?" UNEXPECTED!
        assertEquals(2, mo.groupCount()); // UNEXPECTED!
    }
}