Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8294048

CopyOnWriteArrayList.clone() can't use new lock

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      Code show as below,it will overwrite the old lock with the resetLock method.Because the lock is modified by final, so it will not really be overridden.And then different lists will have conflicts of lock.

      public Object clone() {
              try {
                  @SuppressWarnings("unchecked")
                  CopyOnWriteArrayList<E> clone =
                      (CopyOnWriteArrayList<E>) super.clone();
                  clone.resetLock();
                  return clone;
              } catch (CloneNotSupportedException e) {
                  // this shouldn't happen, since we are Cloneable
                  throw new InternalError();
              }
          }
      private void resetLock() {
              UNSAFE.putObjectVolatile(this, lockOffset, new ReentrantLock());
          }


      FREQUENCY : always


            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: