title: ConcurrentModificationException in LinkedList
body: <p>I am trying to designing a software that convert a flowchart into java or any other code. However I repeatedly getting the ConcurrentModificationException.. 
  But I can't use a boolean to prevent concurrentModification, because access to the linked list happens in various places.</p>
  
  <p>So as a solution I created the below adapter class. However it also throws the same exception from next method. Are there any other solution or if can, plz let me know how to modify my codes... </p>
  
  <p>thank you very much...</p>
  
  <pre><code>import java.util.Iterator;
  import java.util.LinkedList;
  
  public class LinkedListAdapter&lt;T&gt; extends LinkedList&lt;T&gt;{
  
  @Override
  public boolean add(T t){
  
      boolean b;
  
      synchronized(this){
          b = super.add(t);
      }
  
      return b;
  }
  
  @Override
  public T remove(){
  
      T t;
  
      synchronized(this){
          t = super.remove();
      }
  
      return t;
  }
  
  @Override
  public Iterator&lt;T&gt; iterator(){
  
      final LinkedListAdapter&lt;T&gt; adap = this;
  
      return 
          new Iterator&lt;T&gt;(){
  
          private Iterator&lt;T&gt; iter;
  
          {
              synchronized(adap){
                  iter = LinkedListAdapter.this.getIterator();
              }
          }
  
          @Override
          public boolean hasNext() {
  
              boolean b;
  
              synchronized(adap){
                  b = iter.hasNext();
              }
  
              return b;
          }
  
          @Override
          public T next() {
  
              T t;
  
              synchronized(adap){
                  t = iter.next();
              }
  
              return t;
          }
  
          @Override
          public void remove() {
              throw new UnsupportedOperationException();
          }
      };
  }
  
  protected Iterator&lt;T&gt; getIterator() {
  
      Iterator&lt;T&gt; iter;
  
      synchronized(this){
          iter = super.iterator();
      }
  
      return iter;
  }
  }
  </code></pre>