title: Java ConcurrentModificationException at list element access
body: <p>Can someone please explain to me why do I get a <code>ConcurrentModificationException</code> if I just want to access an element of the list? </p>
  
  <p>I was under impression that <code>ConcurrentModificationException</code> is thrown only when one thread iterates over a collection and another one tries to modify it. This is not my case though. I just want to get an element of the list.</p>
  
  <p>Here is a code snippet which reproduces my problem (please don't judge the logic, I just wanted to reproduce the problem):</p>
  
  <pre><code>private static void checkConcurrentModificationException(){
  
      List&lt;String&gt; stringSpan = new ArrayList&lt;String&gt;();
      List&lt;List&lt;String&gt;&gt; clausesStrings = new ArrayList&lt;List&lt;String&gt;&gt;();
      List&lt;String&gt; testStringList = new ArrayList&lt;String&gt;();
  
      for (int i = 0; i &lt; 121; i++) {
          testStringList.add("abc");
      }
  
      for (int i = 0; i &lt; testStringList.size(); i++) {
          stringSpan.clear();
          if (i%2==0) {
              if (i&gt;3) {
                  for (int j = i+1; j &lt; testStringList.size(); j++) {
                      if (j&gt;i+4 || j&gt;=testStringList.size()-1) {
                          stringSpan = testStringList.subList(i, j); //might be the problem
                          clausesStrings.add(stringSpan);
                          break;
                      }
                  }
              }
          } 
      }
      System.out.println("Clause list size: "+clausesStrings.size());
      System.out.println("First clause: "+clausesStrings.get(0));
  }
  </code></pre>
  
  <p>I analyzed the instructions and came to a conclusion that the problem lies in the <code>stringSpan = testStringList.subList(i, j);</code> but I'm not quite sure what happens behind and why it fails. Also, I tried to copy(without reference) the resulting list of lists <code>clausesStrings</code> to a new one but no luck so far.</p>