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

Wrong order of variable initialization may lead to incorrect behavior

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.1.2
    • 3.1.3, 3.0.4, 3.2.1, 3.3.0
    • Spark Core
    • 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

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

            Dates

              Created:
              Updated:
              Resolved: