Hi Folks,

While working on RandomStringGenerator I found when I'm doing .substring on
generated random string its failing intermittently with sequence of
surrogate pair.
same bug was raised in commons-lang
https://issues.apache.org/jira/browse/LANG-100

Is this possible bug with RandomStringGenerator ? or is this expected ?

@Test
public void testSubStringWithSurrogatePair() {
    final int size = 5000;
    final Charset charset = Charset.forName("UTF-8");
    RandomStringGenerator generator = new
RandomStringGenerator.Builder().build();
    String orig = generator.generate(size).substring(0,2500);

    final byte[] bytes = orig.getBytes(charset);
    final String copy = new String(bytes, charset);

    for (int i=0; i < orig.length() && i < copy.length(); i++) {
        final char o = orig.charAt(i);
        final char c = copy.charAt(i);
        assertEquals("differs at " + i + "(" + Integer.toHexString(new
Character(o).hashCode()) + "," +
                Integer.toHexString(new Character(c).hashCode()) + ")", o,
c);
    }

}

Regards,
Amey


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to