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

compiler incorrectly optimizes out empty synchronized blocks

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.1
    • 1.1
    • tools
    • 1.1
    • sparc
    • solaris_2.5
    • Not verified

      The compiler does not generate any code for a synchronized statement with no
      code in its block (apparently for optimization purposes). This causes, for
      example, the following NOT to throw a NullPointerException as specified in the
      JLS 14.17 (page 289):

      synchronized (null) {}

      And there are important semantics lost by this optimization in the non-null
      case as well, such as synchronizing the variables in the thread's working
      memory and guaranteeing that the thread will not continue execution until at
      least the current holder of the given lock has released it.

            fyellinsunw Frank Yellin (Inactive)
            peterjones Peter Jones (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: