# ArrayIndexOutOfBoundsException when loading CSV

**URL:** <https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554>\
**Category:** Import / Export\
**Tags:** apoc, load-csv, import\
**Created:** [June 28, 2021, 8:28pm UTC](https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554 "2021-06-28T20:28:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SandroMartens](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/sandromartens/32/18912_2.png) [@SandroMartens](https://community.neo4j.com/u/SandroMartens)\
**Post date:** [June 28, 2021, 8:28pm UTC](https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554/1 "2021-06-28T20:28:07Z")

</div>

Hi, I want to import a csv table with tweets from twitter. But I get the error message:

> Failed to invoke procedure `apoc.load.csv`: Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 4 out of bounds for length 4

My Code is:

```auto
CALL apoc.load.csv("conversations_until_2021_06_18.tsv", {
  sep: "TAB",
  arraySep: ",",
  skip: 100000,
  mapping: {
    hashtags: {array: true},
    mentions: {array: true},
    ref_id: {array: true},
    reply_count: {type: "int"},
    retweet_count: {type: "int"},
    quote_count: {type: "int"},
    like_count: {type: "int"}
    }
  }
)
YIELD map AS tweet
CREATE (t:Tweet)
SET t = tweet

```

Please provide the following information if you ran into a more serious issue:

I'm using Neo4j v4.3.1, Desktop v1.4.5

An example:

```auto
comment_type	conversatoin_id	text	author_id	tweet_id	ref_type	ref_id	in_reply_to_user_id	created_at	mentions	url	hashtags	like_count	quote_count	reply_count	retweet_count	reply_settings
side	1234 @url https://t.co/... 345 5678 replied_to	564465 4566 2021-04-28T15:55:42.000Z	ABaerbock, ArminLaschet	https://twitter.com/... NaN	0	0	0	0	everyone

```

One of my files works fine, but the second produces this error. According to this [this](https://stackoverflow.com/questions/56563157/neo4js-client-error-apoc-load-csv-failed-procedure-caused-by-arrayindexoutofbou) question there my be a problem with a line in the file. But how to find that line? I have no idea where an array of length 4 could be.

---

<div class="post-metadata">

**Author:** ![giuseppe\_villan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/giuseppe_villan/32/11871_2.png) [@giuseppe\_villan](https://community.neo4j.com/u/giuseppe_villan)\
**Post date:** [June 30, 2021, 9:57am UTC](https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554/2 "2021-06-30T09:57:46Z")

</div>

There seems to be some "fake tabs" in your file.  
Can be solved by replacing them.  
You can do it for example with IntelliJ, opening the file, then `Replace`, and substitute `[]+` (that is, 1 or more spaces) with `\t` (selecting the `Regex` option).

Obviously, you could also delete spaces that you don't want to delete, in that case you have to replace only what you need

Yes, the error message is unclear, but unfortunately it seems to depend on an external library ([http://opencsv.sourceforge.net/](http://opencsv.sourceforge.net/))

---

<div class="post-metadata">

**Author:** ![SandroMartens](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/sandromartens/32/18912_2.png) [@SandroMartens](https://community.neo4j.com/u/SandroMartens)\
**Post date:** [June 30, 2021, 1:35pm UTC](https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554/3 "2021-06-30T13:35:17Z")

</div>

Thanks for the input. What do you mean by "fake tabs"? I have some text with spaces, so i cannot simply replace them.

I deleted some quotation marks and brackets from the file. Could this cause the problem?

---

<div class="post-metadata">

**Author:** ![giuseppe\_villan](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/giuseppe_villan/32/11871_2.png) [@giuseppe\_villan](https://community.neo4j.com/u/giuseppe_villan)\
**Post date:** [July 1, 2021, 10:49am UTC](https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554/4 "2021-07-01T10:49:30Z")

</div>

I don't think the missing quotation marks cause the problem.

For "fake tabs" I mean some column separators which are not actually tab characters,  
but instead of multiple white spaces.

In simple terms, if you copy and paste your example in VsCode, IntelliJ or any other editor  
and try to search "\t" (using "Regular Expression" option),  
you will see that some are not tab separated. For example from `1234` and `@url` there are 2 spaces instead of 1 tab (this causes the error).

---

<div class="post-metadata">

**Author:** ![SandroMartens](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/sandromartens/32/18912_2.png) [@SandroMartens](https://community.neo4j.com/u/SandroMartens)\
**Post date:** [July 1, 2021, 1:30pm UTC](https://community.neo4j.com/t/arrayindexoutofboundsexception-when-loading-csv/40554/5 "2021-07-01T13:30:02Z")

</div>

I think I found my problem. Some of my strings ended with a Backslash `\`. This escapes the following tab. Using `\\` seems to solve this.

> **[OpenCSV: Properly Handling Backslashes - DZone](https://dzone.com/articles/properly-handling-backslashes-using-opencsv)**
>
> Using OpenCSV and running into trouble with backslashes? Here is what is causing your problems when reading and writing CSV data and how to fix them.
