Copy String chars to char array by TextBuffer fails with ArrayIndexOutOfBoundsException
Related jackson-core version is 2.0.4.
In com.fasterxml.jackson.core.util.TextBuffer line 498 expand( len ) is called which results in setting the _currentSegment to MAX_SEGMENT_LEN, even when the segment size is supposed to grow.
Thanks in advance for your support with this!
Related test is given below:
package europass.ewa.services.conversion.xml;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.util.Random;
import org.junit.Test;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
public class BytesToXmlTest{
@Test
public void write256KBData() throws JsonGenerationException, JsonMappingException, IOException {
testWriteData(256);
}
@Test( expected=JsonMappingException.class )
public void write384KBData() throws JsonGenerationException, JsonMappingException, IOException {
testWriteData(384);
}
public void testWriteData(int kb) throws JsonGenerationException, JsonMappingException, IOException {
Random r = new Random(1);
Data data = new Data();
data.bytes = new byte[1024*kb];
r.nextBytes(data.bytes);
String xml = new XmlMapper().writeValueAsString(data);
assertThat(xml, is(notNullValue()));
}
public static class Data {
@JsonProperty
byte[] bytes;
}
}
Ok: I will try to recreate this with basic JsonGenerator, to ensure it does not rely on use of XmlMapper.
Hmmh. I can not reproduce the problem, although I can see what needs fixing. I will write a simpler test for TextBuffer to work around this.
Easy enough to reproduce directly, fix. Will get fix done later today, checked in. Thanks again!
Fixed.
Many thanks for the fix! Could you please let me know, when are you planning to have the next tag release? Will this be 2.0.5?
Yes, this would be 2.0.5. No concrete plans for 2.0.5, but within month most likely.