-
-
Notifications
You must be signed in to change notification settings - Fork 820
Closed
Description
When feeding a non-blocking parser, the input array offset leaks into the offsets reported by getCurrentLocation() and getTokenLocation().
For example, feeding with an offset of 7 yields tokens whose reported locations are 7 greater than they should be. Likewise the current location reported by the parser is 7 greater than the correct location.
It's not possible for a user to work around this issue by subtracting 7 from the reported locations, because the token location may have been established by an earlier feeding with a different offset.
Jackson version: 2.9.8
Unit test:
import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.core.async.ByteArrayFeeder;
import org.junit.Test;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertEquals;
public class FeedingOffsetTest {
@Test
public void inputOffsetShouldNotAffectLocations() throws Exception {
JsonFactory jsonFactory = new JsonFactory();
JsonParser parser = jsonFactory.createNonBlockingByteArrayParser();
ByteArrayFeeder feeder = (ByteArrayFeeder) parser.getNonBlockingInputFeeder();
byte[] input = "[[[".getBytes(UTF_8);
feeder.feedInput(input, 2, 3);
assertEquals(JsonToken.START_ARRAY, parser.nextToken());
assertEquals(1, parser.getCurrentLocation().getByteOffset()); // ACTUAL = 3
assertEquals(1, parser.getTokenLocation().getByteOffset()); // ACTUAL = 3
feeder.feedInput(input, 0, 1);
assertEquals(JsonToken.START_ARRAY, parser.nextToken());
assertEquals(2, parser.getCurrentLocation().getByteOffset());
assertEquals(2, parser.getTokenLocation().getByteOffset());
}
}Metadata
Metadata
Assignees
Labels
No labels