LUCENE-9085: Fix assertion in CharacterUtils (#1067)

This commit is contained in:
Daiki Tsuzuku 2019-12-09 16:32:07 +09:00 committed by Adrien Grand
parent df508ffe01
commit 79007128e3
2 changed files with 13 additions and 2 deletions

View File

@ -53,7 +53,7 @@ public final class CharacterUtils {
*/
public static void toLowerCase(final char[] buffer, final int offset, final int limit) {
assert buffer.length >= limit;
assert offset <=0 && offset <= buffer.length;
assert 0 <= offset && offset <= buffer.length;
for (int i = offset; i < limit;) {
i += Character.toChars(
Character.toLowerCase(
@ -70,7 +70,7 @@ public final class CharacterUtils {
*/
public static void toUpperCase(final char[] buffer, final int offset, final int limit) {
assert buffer.length >= limit;
assert offset <=0 && offset <= buffer.length;
assert 0 <= offset && offset <= buffer.length;
for (int i = offset; i < limit;) {
i += Character.toChars(
Character.toUpperCase(

View File

@ -32,6 +32,17 @@ import org.junit.Test;
*/
public class TestCharacterUtils extends LuceneTestCase {
public void testLowerUpper() throws IOException {
Reader reader = new StringReader("ABc");
CharacterBuffer buffer = CharacterUtils.newCharacterBuffer(3);
assertTrue(CharacterUtils.fill(buffer, reader));
assertEquals(3, buffer.getLength());
CharacterUtils.toLowerCase(buffer.getBuffer(), 1, 3);
assertEquals("Abc", new String(buffer.getBuffer()));
CharacterUtils.toUpperCase(buffer.getBuffer(), 1, 3);
assertEquals("ABC", new String(buffer.getBuffer()));
}
public void testConversions() {
final char[] orig = TestUtil.randomUnicodeString(random(), 100).toCharArray();
final int[] buf = new int[orig.length];