Harmony
  1. Harmony
  2. HARMONY-6677

[classlib][concurrent] NegativeArraySizeException reported in ArrayBlockingQueue under load

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 6.0M3
    • Fix Version/s: 6.0M3
    • Component/s: Classlib
    • Labels:
      None
    • Environment:
      All Operating Systems
    • Patch Info:
      Patch Available
    • Estimated Complexity:
      Moderate

      Description

      The extract() and the removeAt() methods in the ArrayBlockingQueue class do not have a bounds check for the count variable and hence a NegativeArraySizeException is reported when this class is load tested, with multiple threads.

        Activity

        Hide
        Prashanth KS added a comment -

        The extract() method is called by poll(), poll () with args and take().
        The removeAt() method is called by the remove() and the Iterator - remove()

        The "count" variable is decremented in both extract() and removeAt(). When I ran the test using a stress engine, count got decremented and became negative. Please note that in some of the above methods, an interruptible lock is used and has the chance of being woken up in the middle, lets say when the count becomes 0. Meanwhile, another thread could get into the extract(). Now without any condition checks here, I would get an NegativeArraySize exception, which is what I got when I ran the multi-threaded tests.

        So using the "count" condition clauses inside the extract() and the removeAt() seemed to be the better option, rather than trying to implement these conditions in the calling methods. Please let me know if you need the tests for these. I can send it to you offline.

        Show
        Prashanth KS added a comment - The extract() method is called by poll(), poll () with args and take(). The removeAt() method is called by the remove() and the Iterator - remove() The "count" variable is decremented in both extract() and removeAt(). When I ran the test using a stress engine, count got decremented and became negative. Please note that in some of the above methods, an interruptible lock is used and has the chance of being woken up in the middle, lets say when the count becomes 0. Meanwhile, another thread could get into the extract(). Now without any condition checks here, I would get an NegativeArraySize exception, which is what I got when I ran the multi-threaded tests. So using the "count" condition clauses inside the extract() and the removeAt() seemed to be the better option, rather than trying to implement these conditions in the calling methods. Please let me know if you need the tests for these. I can send it to you offline.
        Hide
        Regis Xu added a comment -

        'count' is protected by 'lock', also extract() and removeAt(), and before invoking extract() and removeAt(), there has check to make sure 'count' not zero.
        So I can't see any chance that 'count' could be invalidate in extrac() and removeAt().

        Show
        Regis Xu added a comment - 'count' is protected by 'lock', also extract() and removeAt(), and before invoking extract() and removeAt(), there has check to make sure 'count' not zero. So I can't see any chance that 'count' could be invalidate in extrac() and removeAt().
        Prashanth KS made changes -
        Fix Version/s 6.0M4 [ 12315338 ]
        Fix Version/s 6.0M3 [ 12315055 ]
        Prashanth KS made changes -
        Field Original Value New Value
        Attachment 001_HARMONY_6677.patch [ 12459877 ]
        Hide
        Prashanth KS added a comment -

        Patch for the reported issue

        Show
        Prashanth KS added a comment - Patch for the reported issue
        Prashanth KS created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Prashanth KS
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development