Ben
Ben

Reputation: 1116

Jackson CSV Writter throws ArrayIndexOutOfBoundsException

I have a weird error, which sometime happens sometime doesn't.

Using the same data with the following version Jackson 1.9.9 with the Jackson CSV Data Formatter 1.9.4 (jackson-dataformat-csv), i get the below error.

java.lang.ArrayIndexOutOfBoundsException 
at java.lang.System.arraycopy(Native Method) 
at org.codehaus.jackson.util.TextBuffer.append(TextBuffer.java:458) 
at org.codehaus.jackson.io.SegmentedStringWriter.write(SegmentedStringWriter.java:69) 
at com.fasterxml.jackson.dataformat.csv.impl.CsvWriter._flushBuffer(CsvWriter.java:514) 
at com.fasterxml.jackson.dataformat.csv.impl.CsvWriter.endRow(CsvWriter.java:252) 
at com.fasterxml.jackson.dataformat.csv.CsvGenerator.finishRow(CsvGenerator.java:579) 
at com.fasterxml.jackson.dataformat.csv.CsvGenerator.close(CsvGenerator.java:277) 
at org.codehaus.jackson.map.ObjectMapper._configAndWriteValue(ObjectMapper.java:2584) 
at org.codehaus.jackson.map.ObjectMapper.writeValueAsString(ObjectMapper.java:2097) 

I also get double comma on some of the columns. My guess is that its a bug within the CsvGenerator.

Upvotes: 1

Views: 765

Answers (2)

Rookie
Rookie

Reputation: 1

You can avoid the ArrayIndexOutOfBound Exception by limiting the property names of the pojo to less than 20. And in case you are using any Decimal Formatters in your code, You are likely to get the exception. 1.9.4 is buggy and 2.0 is definately a better version

Upvotes: 0

StaxMan
StaxMan

Reputation: 116522

It sounds like a bug. But one thing to note is that 1.9.x version is not really being developed, so if possible you would want to use version for Jackson 2.x (latest being 2.1.1).

Upvotes: 1

Related Questions