diff --git a/libs/core/src/test/java/org/elasticsearch/common/CharArraysTests.java b/libs/core/src/test/java/org/elasticsearch/common/CharArraysTests.java index 0e3a2179463ba..368886c7fd3d6 100644 --- a/libs/core/src/test/java/org/elasticsearch/common/CharArraysTests.java +++ b/libs/core/src/test/java/org/elasticsearch/common/CharArraysTests.java @@ -43,12 +43,12 @@ public void testBytesToUtf8Chars() { assertArrayEquals(expectedChars, convertedChars); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/34765") public void testCharsBeginsWith() { assertFalse(CharArrays.charsBeginsWith(randomAlphaOfLength(4), null)); assertFalse(CharArrays.charsBeginsWith(null, null)); assertFalse(CharArrays.charsBeginsWith(null, randomAlphaOfLength(4).toCharArray())); - assertFalse(CharArrays.charsBeginsWith(randomAlphaOfLength(2), randomAlphaOfLengthBetween(3, 8).toCharArray())); + final String undesiredPrefix = randomAlphaOfLength(2); + assertFalse(CharArrays.charsBeginsWith(undesiredPrefix, randomAlphaOfLengthNotBeginningWith(undesiredPrefix, 3, 8))); final String prefix = randomAlphaOfLengthBetween(2, 4); assertTrue(CharArrays.charsBeginsWith(prefix, prefix.toCharArray())); @@ -73,4 +73,12 @@ public void testConstantTimeEquals() { assertFalse(CharArrays.constantTimeEquals(value, other)); assertFalse(CharArrays.constantTimeEquals(value.toCharArray(), other.toCharArray())); } + + private char[] randomAlphaOfLengthNotBeginningWith(String undesiredPrefix, int min, int max) { + char[] nonMatchingValue; + do { + nonMatchingValue = randomAlphaOfLengthBetween(min, max).toCharArray(); + } while (new String(nonMatchingValue).startsWith(undesiredPrefix)); + return nonMatchingValue; + } }