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

(coll) asLifoQueue(...).add(E) should delegate to addFirst, not offerFirst

XMLWordPrintable

    • b69
    • x86
    • windows_xp
    • Verified

      FULL PRODUCT VERSION :
      java version "1.6.0-ea"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b57)
      Java HotSpot(TM) Client VM (build 1.6.0-ea-b57, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]


      A DESCRIPTION OF THE PROBLEM :
      The AsLIFOQueue.add method calls offerFirst on the wrapped collection. The contract for add method is different than the contract for offer method. To ensure correctness the AsLIFOQueue.add should call addFirst on the wrapped Deque.

      REGRESSION. Last worked in version mustang

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a bounded LinkedBlockingDeque and wrap in asLifoQueue.
      2. Fill it with Integers using the add method until it returns false.
      3. Test the asLifoQueue to see if it contains the rejected element. It should not which is a violation of the add method contract.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      IllegalStateException
      [when the queue is full; see http://download.java.net/jdk6/docs/api/java/util/Queue.html#add(E) and http://download.java.net/jdk6/docs/api/java/util/concurrent/LinkedBlockingDeque.html#add(E)]

      ACTUAL -
      false
      [i.e. add() encountered a full queue but did not throw an IllegalStateException]

      REPRODUCIBILITY :
      This bug can be reproduced rarely.

      ---------- BEGIN SOURCE ----------
      import java.util.*;
      import java.util.concurrent.*;

      public class Test {
        public static void main(String[] args) {
          Queue q = Collections.asLifoQueue(new LinkedBlockingDeque(10));
          Integer current = Integer.valueOf(0);
          while(true) {
            current = Integer.valueOf(current.intValue() + 1);
            if(!q.add(current)) {
              System.out.println(q.contains(current));
              break;
            }
          }
        }
      }
      ---------- END SOURCE ----------

            martin Martin Buchholz
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: