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

ArrayBlockingQueue throws Interrupted Exception when it shouldn't

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 6u43
    • core-libs
    • None

      FULL PRODUCT VERSION :
      java version " 1.6.0_43 "
      Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux hilbert 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:35:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Standard linux install

      A DESCRIPTION OF THE PROBLEM :
      My read of the JavaDoc says that a BlockingQueue only throws an InterruptedException if the thread is waiting:

       " InterruptedException - if interrupted while waiting " yet it seems like it always throws an interrupt even if it is not waiting (i.e. the queue is not empty).






      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :

      public static void main(final String[] args) throws InterruptedException {
      BlockingQueue<Integer> bg = new LinkedBlockingQueue<Integer>(2);

      bg.add(1);
      Thread.currentThread().interrupt();

      System.out.println(bg.take()); //Should work
      System.out.println( " YAY " );
      System.out.println(bg.take()); //Should fail


      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should see YAY
      ACTUAL -
      InterruptedException

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test {

      public static void main(final String[] args) throws InterruptedException {
      BlockingQueue<Integer> bg = new LinkedBlockingQueue<Integer>(2);

      bg.add(1);
      Thread.currentThread().interrupt();

      System.out.println(bg.take()); //Should work
      System.out.println(bg.take()); //Should fail


      }


      }

      ---------- END SOURCE ----------

            dl Doug Lea
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: