Skip to content

Commit

Permalink
Fixes a bug that prevented early step-out of a container when positio…
Browse files Browse the repository at this point in the history
…ned on a large scalar value in certain cases.
  • Loading branch information
tgregg committed Oct 31, 2023
1 parent 8d744c6 commit 4099a5b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/com/amazon/ion/impl/IonCursorBinary.java
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ private Event slowStepOutOfContainer() {
if (slowSeek(parent.endIndex - offset)) {
return event;
}
peekIndex = parent.endIndex;
peekIndex = offset;
}
setCheckpointBeforeUnannotatedTypeId();
if (--containerIndex >= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -1723,6 +1724,33 @@ public void reallyLargeString(boolean constructFromBytes) throws Exception {
closeAndCount();
}

@ParameterizedTest
@CsvSource({
"true, true",
"true, false",
"false, true",
"false, false"
})
public void skipReallyLargeStringInContainer(boolean constructFromBytes, boolean incremental) throws Exception {
StringBuilder sb = new StringBuilder();
// 70000 is greater than twice the default buffer size of 32768. This ensures that the string, when skipped,
// will not be fully contained in the buffer.
for (int i = 0; i < 70000; i++) {
sb.append('a');
}
String string = sb.toString();
readerBuilder = readerBuilder.withIncrementalReadingEnabled(incremental);
reader = readerFor("{foo: \"" + string + "\"}", constructFromBytes);
assertSequence(
container(IonType.STRUCT,
next(IonType.STRING)
// This is an early-step out that causes the string value to be skipped.
),
next(null)
);
closeAndCount();
}

@ParameterizedTest(name = "constructFromBytes={0}")
@ValueSource(booleans = {true, false})
public void nopPadInAnnotationWrapperFails(boolean constructFromBytes) throws Exception {
Expand Down

0 comments on commit 4099a5b

Please sign in to comment.