ImageBufferCache does not work as intended

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      The intent in the implementation is to keep the largest buffers in the cache by sorting the array in descending order. However the comparator does not do this and the cache always ends up empty.
      ```
      return Integer.compare(getCapacity(br1), getCapacity(br2));
      ```
      Should be:
      ```
      return Integer.compare(getCapacity(br2), getCapacity(br1));
      ```

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Copy-paste the class and add the code.

      ---------- BEGIN SOURCE ----------
      ```
      static void main() {
      var buffers = List.of(
      getBuffer(4096L),
      getBuffer(8192L),
      getBuffer(16384L)
      );
      buffers.forEach(ImageBufferCache::releaseBuffer);
      System.out.println(Arrays.toString(CACHE.get()));
      }
      ```
      ---------- END SOURCE ----------

      FREQUENCY :
      ALWAYS

            Assignee:
            David Beaumont
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: