title: ArrayIndexOutOfBoundsException - when parsing a csv file
body: <p>I want to transform a csv file. My file looks like that:</p>
  
  <p><img src="https://i.stack.imgur.com/Kdy8O.png" alt="enter image description here"></p>
  
  <p>I am using the <code>opencsv</code> libary to parse my csv. That is my <code>run</code> method to parse the file:</p>
  
  <pre><code>public void run() throws Exception {
  
  
          CSVReader reader = new CSVReader(new FileReader(csvFile), ';');
          String [] nextLine;
          int i = -1;
          String fileName = "";
          String companyName = "";
          String currency = "";
          String writerPath;
          List&lt;String&gt; returnList = null;
          List&lt;String&gt; dateList = null;
  
          while ((nextLine = reader.readNext()) != null &amp;&amp; i &lt; 10) {
              String[] line = nextLine;
              System.out.println(line[0]);
              System.out.println(line);
              i++;
  
              //fileName of the String 
              if(!line[0].contains("NULL")) {
                  fileName = line[0];
              }
  
              writerPath = "C:\\Users\\Desktop\\CSVOutput\\" + fileName + ".csv";
              //write csv file
              CSVWriter writer = new CSVWriter(new FileWriter(writerPath), ';');
  
              //write Header
              String[] entries = "Name;Date;TotalReturn;Currency".split(";");
              writer.writeNext(entries);
  
              //create Content
  
              //companyName of the String 
              if(!line[1].contains("Name")) {
                  companyName = line[1];
                  System.out.println(companyName);
              }
  
              //currency 
              if(!line[2].contains("CURRENCY")) {
                  currency = line[2];
              }
  
  
              //total returns
              returnList = new ArrayList&lt;String&gt;();
              if(line[0].contains("NULL")) {
                  for(int j = 3; j &lt;= line.length; j++) {
                      returnList.add(line[j]); // EXCPETION COMES HERE!
                  }
              }
  
              //"Name;Date;TotalReturn;Currency"
              List&lt;String[]&gt; data = new ArrayList&lt;String[]&gt;();
              for(int m = 0; m &lt;= line.length; m++) {
                  data.add(new String[] {companyName, "lolo", "hereComesTheDateLater", currency});
              }
  
              writer.writeAll(data);
  
              //close Writer
              writer.close();
          }
          System.out.println("Done");
  
  
      }
  
  }
  </code></pre>
  
  <p>I am getting an </p>
  
  <pre><code>java.lang.ArrayIndexOutOfBoundsException: 3039
      at com.TransformCSV.main.ParseCSV.run(ParseCSV.java:78)
      at com.TransformCSV.main.ParseCSV.main(ParseCSV.java:20)
  </code></pre>
  
  <p>at this line: <code>returnList.add(line[j]);</code>?</p>
  
  <p>Why? What are possible ways to fix that?</p>
  
  <p>I really appreciate your answer!</p>