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

Synchronization in BufferedImage.setRGB(int x, int y, int rgb) is not necessary

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 10
    • client-libs
    • None
    • 2d
    • minimal
    • Java API
    • SE

      Summary

      The java.awt.image.BufferedImage class is not thread-safe, but one of its methods was marked as synchronized.

      Problem

      The method setRGB(int x, int y, int rgb) in BufferedImage is synchronized, but all other methods in this class are not. For example the similar methods:

      setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize) and get methods:
      getRGB(int x, int y)
      getRGB(int, int, int, int, int[], int, int).

      Solution

      The synchronized keyword should be removed.

      Specification

      src/java.desktop/share/classes/java/awt/image/BufferedImage.java:
      
          * @param y the Y coordinate of the pixel to set
          * @param rgb the RGB value
          * @see #getRGB(int, int)
          * @see #getRGB(int, int, int, int, int[], int, int)
          */
       -  public synchronized void setRGB(int x, int y, int rgb) {
       +  public void setRGB(int x, int y, int rgb) {
              raster.setDataElements(x, y, colorModel.getDataElements(rgb, null));
          }

            serb Sergey Bylokhov
            serb Sergey Bylokhov
            Philip Race
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: