title: ArrayList.addAll() ConcurrentModificationException
body: <p>I'm facing some really strange problems while implementing a kind of Kademlia bucket in Java 8 (OpenJDK).</p>
  
  <p>I need to get at least a specific number of items from so-called Buckets.
  But that's not the problem.</p>
  
  <p>Somehow, I get sometimes a ConcurrentModificationException while doing closest.addAll() on the ArrayList though it is just used in a single thread and I'm not iterating or doing something like that.</p>
  
  <p>Do you know how to help me?
  Here is my code (I know it's a mess!):</p>
  
  <pre><code>List&lt;Neighbour&gt; getClosest(Node n, int num) {
      ArrayList&lt;Neighbour&gt; closest = new ArrayList&lt;&gt;();
      int missing;
      int walkDown = n.getBucket(me);
      int walkUp = walkDown + 1;
      boolean pleaseBreak = true;
      while (true) {
          missing = num - closest.size();
          if (missing &lt;= 0) {
              return closest;
          }
  
          if (walkUp &gt;= 0 &amp;&amp; walkUp &lt; 160) {
              List&lt;Neighbour&gt; l = buckets[walkUp].getClosest(missing);
              closest.addAll(l);
              if (closest.size() &gt;= missing) {
                  return closest;
              }
              walkUp++;
              pleaseBreak = false;
          }
  
          if (walkDown &gt;= 0 &amp;&amp; walkDown &lt; 160) {
              List&lt;Neighbour&gt; l = buckets[walkDown].getClosest(missing);
              closest.addAll(l);
              if (closest.size() &gt;= missing) {
                  return closest;
              }
              walkDown--;
              pleaseBreak = false;
          }
  
          if (pleaseBreak) {
              return closest;
          }
          pleaseBreak = true;
      }
  }
  </code></pre>