Uploaded image for project: 'Kylin'
  1. Kylin
  2. KYLIN-1563

Unsafe check of initiated in HybridInstance#init()

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • v1.5.2
    • None
    • None

    Description

          private void init() {
              if (initiated == true)
                  return;
      
              synchronized (this) {
                  if (initiated == true)
                      return;
      
                  if (realizationEntries == null || realizationEntries.size() == 0)
                      throw new IllegalArgumentException();
      

      Suppose there are two threads executing the above code.

      Thread1 uses the value read from field initiated in the condition initiated == true. It sees that the condition is false.
      Thread2 checks variable initiated, reading it after Thread1 assigns to initiated but before some of the correlated field assignments take place. It sees the condition initiated == true as being true. It continues on before the critical section has completed, and can read data changed by that critical section while it is in an inconsistent state.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            shaofengshi Shao Feng Shi
            yuzhihong@gmail.com Ted Yu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment