You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RichCharSequenceBase.indexOfAll throws an exception when more than 32 sequences are present in a string:
java.lang.ArrayIndexOutOfBoundsException: Index 32 out of bounds for length 32
at com.vladsch.flexmark.util.sequence.RichCharSequenceBase.indexOfAll(RichCharSequenceBase.java:1489)
at com.vladsch.flexmark.util.sequence.BasedSequenceImplTest.test_indexOfAll(BasedSequenceImplTest.java:20)
This occurs in the current master branch. I have also generated the same bug in v0.42.6.
To Reproduce
This can be seen with the following test:
public class BasedSequenceImplTest {
@Test
public void test_indexOfAll() throws Exception {
final String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
BasedSequence s = BasedSequenceImpl.of(s1);
int[] indices = s.indexOfAll("a");
assertEquals(33, indices.length);
for (int i = 0; i < indices.length; i++) {
assertEquals(i, indices[i]);
}
}
}
Expected behavior
There should be no limit to the number of matching indices returned.
Additional context
Below I have provided a re-implementation of indexOfAll which internally uses an ArrayList so resizing of the array is no longer an issue:
@Override
final public int[] indexOfAll(CharSequence s) {
int length = s.length();
if (length == 0) return EMPTY_INDICES;
ArrayList<Integer> indices = new ArrayList<Integer>();
int pos = 0;
while (true) {
pos = indexOf(s, pos);
if (pos == -1) break;
indices.add(pos);
pos += length;
}
int[] arr = new int[indices.size()];
for(int i = 0; i < indices.size(); i++) {
arr[i] = indices.get(i);
}
return arr;
}
Using the above implementation would mean expandTo and truncateTo would then longer be necessary and so could be removed.
The text was updated successfully, but these errors were encountered:
RichCharSequenceBase.indexOfAll
throws an exception when more than 32 sequences are present in a string:This occurs in the current master branch. I have also generated the same bug in v0.42.6.
To Reproduce
This can be seen with the following test:
Expected behavior
There should be no limit to the number of matching indices returned.
Additional context
Below I have provided a re-implementation of
indexOfAll
which internally uses an ArrayList so resizing of the array is no longer an issue:Using the above implementation would mean
expandTo
andtruncateTo
would then longer be necessary and so could be removed.The text was updated successfully, but these errors were encountered: