Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-36717

Wrong order of variable initialization may lead to incorrect behavior

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.1.2
    • Fix Version/s: 3.2.0, 3.1.3, 3.0.4, 3.3.0
    • Component/s: Spark Core
    • Labels:
      None

      Description

      Incorrect order of variable initialization may lead to incorrect behavior, Related code: TorrentBroadcast.scala , TorrentBroadCast will get wrong checksumEnabled value after initialization, this may not be what we need, we can move L94 front of setConf(SparkEnv.get.conf) to avoid this.

      Supplement:

      Snippet 1:

      class Broadcast {
        def setConf(): Unit = {
          checksumEnabled = true
        }
        setConf()
        var checksumEnabled = false
      }
      
      println(new Broadcast().checksumEnabled)

      output:

      false

      Snippet 2:

      class Broadcast {
        var checksumEnabled = false
        def setConf(): Unit = {
          checksumEnabled = true
        }
        setConf()
      }
      
      println(new Broadcast().checksumEnabled)

      output: 

      true

        Attachments

          Activity

            People

            • Assignee:
              Li Jianmeng Jianmeng Li
              Reporter:
              Li Jianmeng Jianmeng Li
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: