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

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

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 10
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
      2d
    • Compatibility Risk:
      minimal
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      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));
          }

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved: